
Matlab.In an assignment A(I) = B, the number of elements in B and I must be the same.
Publicado por David (2 intervenciones) el 22/05/2014 13:11:33
Buenas, me sale el error In an assignment A(I) = B, the number of elements in B and I must be the same. Error in Ejercicio_3_1 (line 35) x(i+1)=x(i)+(k1+2*k2+2*k3+k4)/6; cuando ejecuto esta función en Matlab y no sé como solucionarlo. Gracias por adelantado a todo el que me pueda echar una mano con mi problema.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function [t,x,y,z] =Ejercicio_3_1(f,g,m,t0,T,x0,y0,z0,h)
f=@(t,x,y,z)f;
g=@(t,x,y,z)g;
m=@(t,x,y,z)m;
N=(T-t0)/h;
t=t0:h:T;
x=zeros(1,length(t));
y=zeros(1,length(t));
z=zeros(1,length(t));
x(1)=x0; y(1)=y0;z(1)=z0;
for i=1:(length(x)-1)
k1=h*f(t(i),x(i),y(i),z(i));
l1=h*g(t(i),x(i),y(i),z(i));
r1=h*m(t(i),x(i),y(i),z(i));
k2=h*f(t(i)+h/2,x(i)+k1/2,y(i)+l1/2,z(i)+r1/2);
l2=h*g(t(i)+h/2,x(i)+k1/2,y(i)+l1/2,z(i)+r1/2);
r2=h*m(t(i)+h/2,x(i)+k1/2,y(i)+l1/2,z(i)+r1/2);
k3=h*f(t(i)+h/2,x(i)+k2/2,y(i)+l2/2,z(i)+r2/2);
l3=h*g(t(i)+h/2,x(i)+k2/2,y(i)+l2/2,z(i)+r2/2);
r3=h*m(t(i)+h/2,x(i)+k2/2,y(i)+l2/2,z(i)+r2/2);
k4=h*f(t(i)+h,x(i)+k3,y(i)+l3,z(i)+r3);
l4=h*g(t(i)+h,x(i)+k3,y(i)+l3,z(i)+r3);
r4=h*m(t(i)+h,x(i)+k3,y(i)+l3,z(i)+r3);
x(i+1)=x(i)+(k1+2*k2+2*k3+k4)/6;
y(i+1)=y(i)+(l1+2*l2+2*l3+l4)/6;
z(i+1)=z(i)+(r1+2*r2+2*r3+r4)/6;
Valora esta pregunta


0