how to get updated value of function everytime in the loop

2 views (last 30 days)
Hello. I am using the below code in the loop and here is the problem area. When I use the code(following)
for i=1:100,
G=i;
A=[-1/10 0;G -(1+10*G)/10];
B=[2 2 0;2 G G];
C=[1 -1];
I=[1 0;0 1];
syms s
Q=C*((s*I-A)^(-1))*B;
Q(2);
Q(3);
syms t
M=(ilaplace(Q(2),s,t))^2;
N=(ilaplace(Q(3),s,t))^2;
m=integral(M,0,Inf);
n=integral(N,0,Inf);
Sw=1;Sv=100;
Ess(i,:)=Sw*m+Sv*n;
We(i,:)=Sw*m;Ve(i,:)=Sv*n;
end
Error using integral (line 83) First input argument must be a function handle.
*now i think the error is in the line where I use M=(ilaplace(Q(2),s,t))^2; and N=(ilaplace(Q(3),s,t))^2;, but how else I can achieve to calculate the integral as each time the value of G is different in each loop and hence I cannot write M and N as function of t because it changes every time the loop is executed depending on the value of G. *

Accepted Answer

Walter Roberson
Walter Roberson on 28 Feb 2014
Edited: Walter Roberson on 28 Feb 2014
ilaplace is a symbolic transform, giving you a symbolic result. You need to convert the symbolic result to a function handle. See matlabFunction() for that.
Or you could consider using symbolic integration, int() instead of integral()
  2 Comments
upinderjeet
upinderjeet on 28 Feb 2014
Dont you think that in both the cases you recommend, I still have to write the expression for that symbolic function before I cud use a function handle or int. If I am right then how can I cater to the changing value of that expression every time the new loop is being executed.

Sign in to comment.

More Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!