Filter löschen
Filter löschen

how to get updated value of function everytime in the loop

1 Ansicht (letzte 30 Tage)
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. *

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 28 Feb. 2014
Bearbeitet: Walter Roberson am 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 Kommentare
upinderjeet
upinderjeet am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Function Creation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by