soniya_shah asked . 2021-10-21

How to solve an equation system using a interp1-variable

Hello everyone,
 
I'm trying to solve equations in a Matlab function that is part of a Simulink model.
 
One of those two equations is an interpolation of a given array.
 
% variable definiton
% T                     function argument
% p = f(T)              values are given in form of a 69x2 double
% a | b | c | h         constants / parameters (defined or calculated beforehand)

% equations
% eqn 1
% p = interp1(p(:,1),p(:,2),T)
% eqn 2
% h = a * T + p * (b + c * T)

% As I am used to solve equations with my pocket calculator I quickly found something like this while browsing:

syms T
solve (h == a * T + interp1(p(:,1),p(:,2),T) * (b + c * T),T);

% Unfortunately I do not have the required toolbox to solve equations which is why I need to find a work-around

% my next idea was to use an iteration to solve this (which I did not formulate and test until now)
% it would be something like that though:

for T = 1:100
    p = interp1(p(:,1),p(:,2),T);
    h_iter = a * T + p * (b + c * T);
    if h_iter > h - h_marge | h_iter < h + h_marge
        break
    end
end

% with h_marge being a predefined value for accuracy tolerance
I would like to avoid such an iterational process since the iteration has to be done each simulation-step which could cause long simulation times
 
depending on the accuracy and the initial condition(s) I determine.
 
Thus, I wanted to ask you if there is another method / solution to solving that problem.
 

solve , equation , interp1 , iteration , simulink , matlab-function

Expert Answer

Prashant Kumar answered . 2024-11-23 01:39:16

interp1 is incompatible with symbolic parameters. You CANNOT use interp1 with solve. Period. So wherever you found that snippet of code, they were wrong.
 
You can use a tool like fzero with interp1. fzero and interp1 are compatible.
 
Next, looking at your problem, this is actually a TWO variable problem, with two equations. That is, we have known constants, a,b,c,h. And there are two unknowns. Sadly, you seem to be using p in two places at once, both as an array of known elements, and as a variable. And that is confusing as hell.
 
So I'll make the assumption that you have two variales, I'll call then T and p_T. That is p_T is given as:
 
p_T = interp1(p(:,1),p(:,2),T)
 
So, if I knew the value of T, then I could compute P_T. And then we have a second equation:
 
h = a * T + p_T * (b + c * T)
 
Now we can just substitute P_T in there. This reduces the problem to ONE equation, in one unknown, where you can use fzero. I've re-arranged it to be something you can see as a problem for fzero.
 
a * T + interp1(p(:,1),p(:,2),T) * (b + c * T) - h = 0
 
Now, given the variables a,b,c,h and the array p are defined as MATLAB variables in your workspace, set it up as:
 
fun = @(T) a * T + interp1(p(:,1),p(:,2),T) * (b + c * T) - h;
Tfinal = fzero(fun,[p(1,1),p(end,1)]);
That call will set a bracket on T, such that T must always lie between P(1,1) and P(69,1). That must make sense, since interp1 cannot intelligently evaluate its function beyond those limits anyway.
 
Again, a,b,c,h and p must all be previously defined in your workspace for that to work.
 
 

vq = interp1(x,v,xq) returns interpolated values of a 1-D function at specific query points using linear interpolation. Vector x contains the sample points, and v contains the corresponding values, v(x). Vector xq contains the coordinates of the query points.

If you have multiple sets of data that are sampled at the same point coordinates, then you can pass v as an array. Each column of array v contains a different set of 1-D sample values.


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.