How to solve an equation system using a interp1-variable

Technical Source
3 min readOct 21, 2021

--

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.

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

Expert Answer

Prashant Kumar answered . 2021–10–21 06:59:13

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)

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet