Matlab - Error: DImensions must agree

 
Vista:

Error: DImensions must agree

Publicado por Maria (27 intervenciones) el 16/12/2015 13:39:36
Hola!! Os adjunto el programa el error que me aparece es: Error using +
Matrix dimensions must agree.

Es un poco largo el programa pero sencillo de entender. Gracias!!
es una ode45 de osciladores, el problema esta en : f=@(t,theta)( w + (K*R)*sin(phi-theta) );

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
%Creamos un vector w que contiene N frecuencias aleatorias distribuidas segun lorentziana.
 
N=input(' Introduce el numero de osciladores :');
a=0;
b=1;
G=a+(b-a)*rand(1,N);
c=0.5;
w=c*tan(G*pi-pi/2);
 
%K= constante, ponemos 3
K=3;
 
 
%Calculamos unas condiciones iniciales para las thetha(i) que la vamos a llamar
%xo(dentro del bucle de tiempo)
 
z=0;
v=2*pi;
xo=z+(v-z)*rand(1,N)
 
%Tenemos que calcular R que va entre 0 y 1 y el angulo medio phi.
 
 
dt=0.5; %intervalos de tiempo
R=0;
phi=0;
theta=xo;
 
for t=2:1:202      %200 (t)time steps
 
  rx=0;
  ry=0;
 
    TO=(t-1)*dt; %tiempo inicial
    T=t*dt;      %tiempo final dentro del intervalo
 
 
    %parámetros ode45: tiempo integracion y opciones
    tspan=[TO   T];
    options=odeset('RelTol',1e-6);
 
 
 
 
    %funcion que queremos integrar
  -->  f=@(t,theta)( w + (K*R)*sin(phi-theta) );
 
    %ode45 integra funcion
    [t,theta]=ode45(f,tspan,xo,options);
 
 
    yo=theta;
 
    rx=(1/N)*cos(yo);
    RX=sum(rx);
 
    ry=(1/N)*sin(yo);
    RY=sum(ry);
 
  %bucle N
 
R=sqrt(RX^2+RY^2);
 
phi=atan2(RY,RX);
 
 
plot(T,R);
hold on
 
end  %bucle t

--> Error using +: Dimension must agree en ( f=@(t,theta)( w + (K*R)*sin(phi-theta) ); )
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 JESUS DAVID ARIZA ROYETH
Val: 3.309
Plata
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

Error: DImensions must agree

Publicado por JESUS DAVID ARIZA ROYETH (1818 intervenciones) el 19/07/2018 19:00:19
Ejemplo de ode45 y encontrar los máximos locales del intervalo :

1
2
3
4
5
6
7
[t,y] = ode45(@(t,y) cos(t.^2), [0.9 55], 0);
[~,w] = findpeaks(y);
figure
plot(t,y,'-b')
hold on
plot(t(w),y(w),'*r')
fprintf('tiene  %i máximos locales en este intervalo  \n',length(w))


graf
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