Matlab - Matlab.In an assignment A(I) = B, the number of elements in B and I must be the same.

 
Vista:
sin imagen de perfil

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
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Dave
Val: 497
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

Matlab.In an assignment A(I) = B, the number of elements in B and I must be the same.

Publicado por Dave (1094 intervenciones) el 23/05/2014 12:19:29
Hola David;

El código que intentas desarrollar, si no me equivoco es similar al algoritmo del método de solución de ecuaciones ordinarias de Runge Kutta de 4 orden.

Sobre el error que mencionar, habría que revisar tu código completo, solo colocaste hasta la línea 26 y el error menciona a la línea 35.

Espero que sea de alguna ayuda.

Saludos
Dave Correa
[email protected]
[email protected]
Servicios de Programación Matlab
http://fismatlab.org
http://fismatlab.blogspot.com
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

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 23/05/2014 16:00:37
En efecto, el algoritmo que intento desarrollar es el método de resolución de Runge-Kutta. Las líneas que faltan son frases explicativas que no tienen nada que ver con el funcionamiento del método que intento desarrollar. El algoritmo está completo pero no sé como solucionar el problema.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de JOSE JEREMIAS CABALLERO
Val: 6.975
Oro
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

Matlab.In an assignment A(I) = B, the number of elements in B and I must be the same.

Publicado por JOSE JEREMIAS CABALLERO (5917 intervenciones) el 25/05/2014 23:52:53
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
29
30
31
32
33
34
35
36
37
38
39
40
41
function [t,x,y,z] =runge_kutta(f,g,m,t0,T,x0,y0,z0,h)
if nargin <1
   syms t xx yy zz
   f1=sin(xx)*cos(yy)*zz*t;
   g1=2*sin(xx)*tan(yy)*sec(zz)*t;
   m1=cos(xx)*tan(yy)*(2*zz)*t;
   t0=0;
   T=2;
   x0=1;
   y0=2;
   z0=-1;
   h=0.1;
end
 
 f=inline(f1,'t','xx','yy','zz');
 g=inline(g1,'t','xx','yy','zz');
 m=inline(m1,'t','xx','yy','zz');
 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;
 end


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
>> [t,x,y,z] =runge_kutta
 
t =
 
         0    0.1000    0.2000    0.3000    0.4000    0.5000    0.6000    0.7000    0.8000    0.9000    1.0000
 
 
x =
 
    1.0000    1.0017    1.0057    1.0059    1.0005    0.9967    0.9834    0.9844    0.9846    0.9854    0.9863
 
 
y =
 
    2.0000    1.9646    1.8339    1.1891    1.6627    1.3403   -1.2200   -1.7983   -3.3401   -3.3708   -3.4110
 
 
z =
 
   -1.0000   -0.9877   -0.9420   -0.7133   -0.8812   -0.7622    0.1834    0.1212   -0.0120   -0.0117   -0.0114

Saludos.
JOSE JEREMÍAS CABALLERO
Asesoría online y Presencial en Matlab
programador en matlab
Servicios de programación matlab
[email protected]
Estimado Usuario de Matlab, el correo es para servicios de programación, toda ayuda gratuita es vía foro.


http://matlabcaballero.blogspot.com

http://www.lawebdelprogramador.com/foros/Matlab/1371532-FORMA_DE_APRENDER_MATLAB.html
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar