I couldn't plot the function because it seems vector length isn't same, please help me in it.

1 vue (au cours des 30 derniers jours)
clear
tc = 30E-9;
P = 0.05;
k= 3E-3;
h = 10E-2;
T =10^3;
time = 0:0.1E-4:4E-4;
a= 3;
func1 = @(z1,x1) (P - z1 - (1 + 2.*z1).*((x1)^2))./T;
func2 = @(z2,x2) (P - z2 - (1 + 2.*z2).*((x2)^2))./T;
func3 = @(z3,x3) (P - z3 - (1 + 2.*z3).*((x3)^2))./T;
func4 = @(z4,x4) (P - z4 - (1 + 2.*z4).*((x4)^2))./T;
func5 = @(z5,x5) (P - z5 - (1 + 2.*z5).*((x5)^2))./T;
func6 = @(z1,x1,x2,x5,o1,o5) z1.*x1 - k.*(x2.*sin(o1) - x5.*sin(o5));
func7 = @(z2,x2,x1,x3,o2,o1) z2.*x2 - k.*(x3.*sin(o2) - x1.*sin(o1));
func8 = @(z3,x3,x4,x2,o3,o2) z3.*x3 - k.*(x4.*sin(o3) - x2.*sin(o2));
func9 = @(z4,x4,x5,x3,o4,o3) z4.*x4 - k.*(x5.*sin(o4) - x3.*sin(o3));
func10 = @(z5,x5,x1,x4,o5,o4) z5.*x5 - k.*(x1.*sin(o5) - x4.*sin(o4));
func11 = @(z1,z2,x2,x1,x5,x3,o1,o5,o2) a.*z1 - a.*z2 - k.*((x2./x1).*cos(o1) + (x5./x1).*cos(o5) - (x3./x2).*cos(o2) - (x1./x2).*cos(o1)) ;
func12 = @(z2,z3,x2,x1,x4,x3,o2,o1,o3) a.*z2 - a.*z3 - k.*((x3./x2).*cos(o2) + (x1./x2).*cos(o1) - (x4./x3).*cos(o3) - (x2./x3).*cos(o2)) ;
func13 = @(z3,z4,x3,x2,x4,x5,o2,o4,o3) a.*z3 - a.*z4 - k.*((x4./x3).*cos(o3) + (x2./x3).*cos(o2) - (x5./x4).*cos(o4) - (x3./x4).*cos(o3)) ;
func14 = @(z4,z5,x4,x5,x3,x1,o4,o3,o5) a.*z4 - a.*z5 - k.*((x5./x4).*cos(o4) + (x3./x4).*cos(o3) - (x1./x5).*cos(o5) - (x4./x5).*cos(o4)) ;
func15 = @(z5,z1,x1,x5,x4,x2,o5,o4,o1) a.*z5 - a.*z1 - k.*((x1./x5).*cos(o5) + (x4./x5).*cos(o4) - (x2./x1).*cos(o1) - (x5./x1).*cos(o5)) ;
z1 = 0;
z2 = 0;
z3 = 0;
z4 = 0;
z5 = 0;
x1 = sqrt(P);
x2 = sqrt(P);
x3 = sqrt(P);
x4 = sqrt(P);
x5 = sqrt(P);
o1 = 0.01;
o2 = 0.01;
o3 = 0.01;
o4 = 0.01;
o5 = 0.01;
n = 100
n = 100
for i = 1:n
b1 = func1(z1(i),x1(i));
c1 = func2(z2(i),x2(i));
d1 = func3(z3(i),x3(i));
e1 = func4(z4(i),x4(i));
f1 = func5(z5(i),x5(i));
g1 = func6(z1(i),x1(i),x2(i),x5(i),o1(i),o5(i));
h1 = func7(z2(i),x2(i),x1(i),x3(i),o2(i),o1(i));
j1 = func8(z3(i),x3(i),x4(i),x2(i),o3(i),o2(i));
k1 = func9(z4(i),x4(i),x5(i),x3(i),o4(i),o3(i));
l1 = func10(z5(i),x5(i),x1(i),x4(i),o5(i),o4(i));
m1 = func11(z1(i),z2(i),x2(i),x1(i),x5(i),x3(i),o1(i),o5(i),o2(i));
n1 = func12(z2(i),z3(i),x2(i),x1(i),x4(i),x3(i),o2(i),o1(i),o3(i));
q1 = func13(z3(i),z4(i),x3(i),x2(i),x4(i),x1(i),o2(i),o4(i),o3(i));
r1 = func14(z4(i),z5(i),x4(i),x5(i),x3(i),x1(i),o4(i),o3(i),o5(i));
s1 = func15(z5(i),z1(i),x1(i),x5(i),x4(i),x2(i),o5(i),o4(i),o1(i));
b2 = func1(z1(i)+((b1*h)/2),x1(i)+((g1*h)/2));
c2 = func2(z2(i)+((c1*h)/2),x2(i)+((h1*h)/2));
d2 = func3(z3(i)+((d1*h)/2),x3(i)+((j1*h)/2));
e2 = func4(z4(i)+((e1*h)/2),x4(i)+((k1*h)/2));
f2 = func5(z5(i)+((f1*h)/2),x5(i)+((l1*h)/2));
g2 = func6(z1(i)+((b1*h)/2),x1(i)+((g1*h)/2),x2(i)+((h1*h)/2),x5(i)+((j1*h)/2),o1(i)+((m1*h)/2),o5(i)+((s1*h)/2));
h2 = func7(z2(i)+((c1*h)/2),x2(i)+((h1*h)/2),x1(i)+((g1*h)/2),x3(i)+((d1*h)/2),o2(i)+((n1*h)/2),o1(i)+((m1*h)/2));
j2 = func8(z3(i)+((d1*h)/2),x3(i)+((j1*h)/2),x4(i)+((k1*h)/2),x2(i)+((h1*h)/2),o3(i)+((q1*h)/2),o2(i)+((n1*h)/2));
k2 = func9(z4(i)+((e1*h)/2),x4(i)+((k1*h)/2),x5(i)+((l1*h)/2),x3(i)+((j1*h)/2),o4(i)+((r1*h)/2),o3(i))+((q1*h)/2);
l2 = func10(z5(i)+((f1*h)/2),x5(i)+((l1*h)/2),x1(i)+((g1*h)/2),x4(i)+((k1*h)/2),o5(i)+((s1*h)/2),o4(i)+((r1*h)/2));
m2 = func11(z1(i)+((b1*h)/2),z2(i)+((c1*h)/2),x2(i)+((h1*h)/2),x1(i)+((g1*h)/2),x5(i)+((l1*h)/2),x3(i)+((j1*h)/2),o1(i)+((m1*h)/2),o5(i)+((s1*h)/2),o2(i)+((n1*h)/2));
n2 = func12(z2(i)+((c1*h)/2),z3(i)+((d1*h)/2),x2(i)+((h1*h)/2),x1(i)+((g1*h)/2),x4(i)+((k1*h)/2),x3(i)+((j1*h)/2),o2(i)+((n1*h)/2),o1(i)+((m1*h)/2),o3(i)+((q1*h)/2));
q2 = func13(z3(i)+((d1*h)/2),z4(i)+((e1*h)/2),x3(i)+((j1*h)/2),x2(i)+((h1*h)/2),x4(i)+((k1*h)/2),x1(i)+((g1*h)/2),o2(i)+((n1*h)/2),o4(i)+((r1*h)/2),o3(i)+((q1*h)/2));
r2 = func14(z4(i)+((e1*h)/2),z5(i)+((f1*h)/2),x4(i)+((k1*h)/2),x5(i)+((l1*h)/2),x3(i)+((j1*h)/2),x1(i)+((g1*h)/2),o4(i)+((r1*h)/2),o3(i)+((q1*h)/2),o5(i)+((s1*h)/2));
s2 = func15(z5(i)+((f1*h)/2),z1(i)+((b1*h)/2),x1(i)+((g1*h)/2),x5(i)+((l1*h)/2),x4(i)+((k1*h)/2),x2(i)+((h1*h)/2),o5(i)+((s1*h)/2),o4(i)+((r1*h)/2),o1(i)+((m1*h)/2));
b3 = func1(z1(i)+((b2*h)/2),x1(i)+((g2*h)/2));
c3 = func2(z2(i)+((c2*h)/2),x2(i)+((h2*h)/2));
d3 = func3(z3(i)+((d2*h)/2),x3(i)+((j2*h)/2));
e3 = func4(z4(i)+((e2*h)/2),x4(i)+((k2*h)/2));
f3 = func5(z5(i)+((f2*h)/2),x5(i)+((l2*h)/2));
g3 = func6(z1(i)+((b2*h)/2),x1(i)+((g2*h)/2),x2(i)+((h2*h)/2),x5(i)+((j2*h)/2),o1(i)+((m2*h)/2),o5(i)+((s2*h)/2));
h3 = func7(z2(i)+((c2*h)/2),x2(i)+((h2*h)/2),x1(i)+((g2*h)/2),x3(i)+((d2*h)/2),o2(i)+((n2*h)/2),o1(i)+((m2*h)/2));
j3 = func8(z3(i)+((d2*h)/2),x3(i)+((j2*h)/2),x4(i)+((k2*h)/2),x2(i)+((h2*h)/2),o3(i)+((q2*h)/2),o2(i)+((n2*h)/2));
k3 = func9(z4(i)+((e2*h)/2),x4(i)+((k2*h)/2),x5(i)+((l2*h)/2),x3(i)+((j2*h)/2),o4(i)+((r2*h)/2),o3(i))+((q2*h)/2);
l3 = func10(z5(i)+((f2*h)/2),x5(i)+((l2*h)/2),x1(i)+((g2*h)/2),x4(i)+((k2*h)/2),o5(i)+((s2*h)/2),o4(i)+((r2*h)/2));
m3 = func11(z1(i)+((b2*h)/2),z2(i)+((c2*h)/2),x2(i)+((h2*h)/2),x1(i)+((g2*h)/2),x5(i)+((l2*h)/2),x3(i)+((j2*h)/2),o1(i)+((m2*h)/2),o5(i)+((s2*h)/2),o2(i)+((n2*h)/2));
n3 = func12(z2(i)+((c2*h)/2),z3(i)+((d2*h)/2),x2(i)+((h2*h)/2),x1(i)+((g2*h)/2),x4(i)+((k2*h)/2),x3(i)+((j2*h)/2),o2(i)+((n2*h)/2),o1(i)+((m2*h)/2),o3(i)+((q2*h)/2));
q3 = func13(z3(i)+((d2*h)/2),z4(i)+((e2*h)/2),x3(i)+((j2*h)/2),x2(i)+((h2*h)/2),x4(i)+((k2*h)/2),x1(i)+((g2*h)/2),o2(i)+((n2*h)/2),o4(i)+((r2*h)/2),o3(i)+((q2*h)/2));
r3 = func14(z4(i)+((e2*h)/2),z5(i)+((f2*h)/2),x4(i)+((k2*h)/2),x5(i)+((l2*h)/2),x3(i)+((j2*h)/2),x1(i)+((g2*h)/2),o4(i)+((r2*h)/2),o3(i)+((q2*h)/2),o5(i)+((s2*h)/2));
s3 = func15(z5(i)+((f2*h)/2),z1(i)+((b2*h)/2),x1(i)+((g2*h)/2),x5(i)+((l2*h)/2),x4(i)+((k2*h)/2),x2(i)+((h2*h)/2),o5(i)+((s2*h)/2),o4(i)+((r2*h)/2),o1(i)+((m2*h)/2));
b4 = func1(z1(i)+((b3*h)),x1(i)+((g3*h)));
c4 = func2(z2(i)+((c3*h)),x2(i)+((h3*h)));
d4 = func3(z3(i)+((d3*h)),x3(i)+((j3*h)));
e4 = func4(z4(i)+((e3*h)),x4(i)+((k3*h)));
f4 = func5(z5(i)+((f3*h)),x5(i)+((l3*h)));
g4 = func6(z1(i)+((b3*h)),x1(i)+((g3*h)),x2(i)+((h3*h)),x5(i)+((j3*h)),o1(i)+((m3*h)),o5(i)+((s3*h)));
h4 = func7(z2(i)+((c3*h)),x2(i)+((h3*h)),x1(i)+((g3*h)),x3(i)+((d3*h)),o2(i)+((n3*h)),o1(i)+((m3*h)));
j4 = func8(z3(i)+((d3*h)),x3(i)+((j3*h)),x4(i)+((k3*h)),x2(i)+((h3*h)),o3(i)+((q3*h)),o2(i)+((n3*h)));
k4 = func9(z4(i)+((e3*h)),x4(i)+((k3*h)),x5(i)+((l3*h)),x3(i)+((j3*h)),o4(i)+((r3*h)),o3(i))+((q3*h));
l4 = func10(z5(i)+((f3*h)),x5(i)+((l3*h)),x1(i)+((g3*h)),x4(i)+((k3*h)),o5(i)+((s3*h)),o4(i)+((r3*h)));
m4 = func11(z1(i)+((b3*h)),z2(i)+((c3*h)),x2(i)+((h3*h)),x1(i)+((g3*h)),x5(i)+((l3*h)),x3(i)+((j3*h)),o1(i)+((m3*h)),o5(i)+((s3*h)),o2(i)+((n3*h)));
n4 = func12(z2(i)+((c3*h)),z3(i)+((d3*h)),x2(i)+((h3*h)),x1(i)+((g3*h)),x4(i)+((k3*h)),x3(i)+((j3*h)),o2(i)+((n3*h)),o1(i)+((m3*h)),o3(i)+((q3*h)));
q4 = func13(z3(i)+((d3*h)),z4(i)+((e3*h)),x3(i)+((j3*h)),x2(i)+((h3*h)),x4(i)+((k3*h)),x1(i)+((g3*h)),o2(i)+((n3*h)),o4(i)+((r3*h)),o3(i)+((q3*h)));
r4 = func14(z4(i)+((e3*h)),z5(i)+((f3*h)),x4(i)+((k3*h)),x5(i)+((l3*h)),x3(i)+((j3*h)),x1(i)+((g3*h)),o4(i)+((r3*h)),o3(i)+((q3*h)),o5(i)+((s3*h)));
s4 = func15(z5(i)+((f3*h)),z1(i)+((b3*h)),x1(i)+((g3*h)),x5(i)+((l3*h)),x4(i)+((k3*h)),x2(i)+((h3*h)),o5(i)+((s3*h)),o4(i)+((r3*h)),o1(i)+((m3*h)));
z1(i+1) = z1(i) + (h/6)*(b1+(2*(b2+b3))+b4);
z2(i+1) = z2(i) + (h/6)*(c1+(2*(c2+c3))+c4);
z3(i+1) = z3(i) + (h/6)*(d1+(2*(d2+d3))+d4);
z4(i+1) = z4(i) + (h/6)*(e1+(2*(e2+e3))+e4);
z5(i+1) = z5(i) + (h/6)*(f1+(2*(f2+f3))+f4);
x1(i+1) = x1(i) + (h/6)*(g1+(2*(g2+g3))+g4);
x2(i+1) = x2(i) + (h/6)*(h1+(2*(h2+h3))+h4);
x3(i+1) = x3(i) + (h/6)*(j1+(2*(j2+j3))+j4);
x4(i+1) = x4(i) + (h/6)*(k1+(2*(k2+k3))+k4);
x5(i+1) = x5(i) + (h/6)*(l1+(2*(l2+l3))+l4);
o1(i+1) = o1(i) + (h/6)*(m1+(2*(m2+m3))+m4);
o2(i+1) = o2(i) + (h/6)*(n1+(2*(n2+n3))+n4);
o3(i+1) = o3(i) + (h/6)*(q1+(2*(q2+q3))+q4);
o4(i+1) = o4(i) + (h/6)*(r1+(2*(r2+r3))+r4);
o5(i+1) = o5(i) + (h/6)*(s1+(2*(s2+s3))+s4);
end
plot(time,o1);
Error using plot
Vectors must be the same length.
hold on
plot(time,o2);
plot(time,o3);
plot(time,o4);
plot(time,o5);
hold off

Réponses (1)

Alan Stevens
Alan Stevens le 8 Sep 2022
Try changing
n = 100
for i = 1:n
to
n = numel(time);
for i = 1:n-1

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by