How to create for loop
Show older comments
I am trying to write a code to determine C(t) as a function of time and tabulate C(t) for t=0-10 units of time for each Kc. I also need to plot C(t) on the same set of axis, as a function of t for each value of Kc.
I was trying to use a for loop to tabulate this is what I have so far. The for loop runs but does not give any actual values it just says "value of Ct1:"
Any help would be greatly apprectaied!
clear;
clc;
syms s t;
Kc1 = 3;
numerator1=[(Kc1*(1/3)) (Kc1*1)];
denominator1=[(1/6) 1 (11/6) (1+Kc1) 0];
roots1=roots(denominator1);
[r1, p1, k1]= residue(numerator1, denominator1);
Ct1= ilaplace((r1(1)/(s-p1(1)))+(r1(2)/(s-p1(2)))+(r1(3)/(s-p1(3)))+k1)
Kc2 = 6;
numerator2=[(Kc2*(1/3)) (Kc2*1)];
denominator2=[(1/6) 1 (11/6) (1+Kc2) 0];
roots2=roots(denominator2);
[r2, p2, k2]= residue(numerator2, denominator2);
Ct2= ilaplace((r2(1)/(s-p2(1)))+(r2(2)/(s-p2(2)))+(r2(3)/(s-p2(3)))+k2)
Kc3 = 9;
numerator3=[(Kc3*(1/3)) (Kc3*1)];
denominator3=[(1/6) 1 (11/6) (1+Kc3) 0];
roots3=roots(denominator3);
[r3, p3, k3]= residue(numerator3, denominator3);
Ct3= ilaplace((r3(1)/(s-p3(1)))+(r3(2)/(s-p3(2)))+(r3(3)/(s-p3(3)))+k3)
Kc4 = 12;
numerator4=[(Kc4*(1/3)) (Kc4*1)];
denominator4=[(1/6) 1 (11/6) (1+Kc4) 0];
roots4=roots(denominator4);
[r4, p4, k4]= residue(numerator4, denominator4);
Ct4= ilaplace((r4(1)/(s-p4(1)))+(r4(2)/(s-p4(2)))+(r4(3)/(s-p4(3)))+k4)
for Ct1 = 1:10
Ct1 = ilaplace((r1(1)/(s-p1(1)))+(r1(2)/(s-p1(2)))+(r1(3)/(s-p1(3)))+k1)
fprintf('value of Ct1: %d\n' , Ct1);
end
Accepted Answer
More Answers (1)
You see the reason (see above) ?
The degree of the denominator is bigger than the degree of the numerator. Thus k1,k2,k3 and k4 are empty.
And Ct1 will still be symbolic and depend on t. Thus printing it as a double will throw an error.
Categories
Find more on Image Analysis 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!








