how to get updated value of function everytime in the loop

1 次查看(过去 30 天)
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. *

采纳的回答

Walter Roberson
Walter Roberson 2014-2-28
编辑:Walter Roberson 2014-2-28
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 个评论
upinderjeet
upinderjeet 2014-2-28
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by