How to parse a Matrix ODE45. Getting simulation error

3 visualizaciones (últimos 30 días)
Shy
Shy el 27 de Jul. de 2020
Comentada: Shy el 27 de Jul. de 2020
Hi Dears!
I am simulating a set of Ordinary Differntial Equations ODEs using ODE45 solver. I need to parse a matrix (i.e. zeta=rand(46,16)) into the ODE45, however I am getting this error:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in OscillatorExample_V2>LinearOscillatorFree (line 26)
y(2)=(-2*zeta*y(2))-(w*y(1));
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in OscillatorExample_V2 (line 9)
[T, Y] = ode45(@LinearOscillatorFree, tspan, initcond, [],zeta);
Can you please help me with this to get the right results? Many thanks in advance!
close all; clear all; clc;
zeta=rand(46,16);
tspan=[0 4700];
initcond= [0 1];
for n = 1:length(zeta)
[T, Y] = ode45(@LinearOscillatorFree, tspan, initcond, [],zeta);
figure(1);
plot(T, Y(:,1));
hold on
end
m= length(Y);
for i=1:m
y(i,:)=feval('LinearOscillatorFree',T(i),Y(i,:),zeta);
end
y=y';
function dy = LinearOscillatorFree(t, y,zeta)
w=0.5;
y(1)=y(2);
y(2)=(-2*zeta*y(2))-(w*y(1));
dy= [y(1); y(2)];
end
  7 comentarios
James Tursa
James Tursa el 27 de Jul. de 2020
Editada: James Tursa el 27 de Jul. de 2020
Your equations don't make sense to me. How can y1 and y2 be scalars and yet zeta be a matrix? The dimensions of the equations don't match. It might make sense for zeta fo be a scalar that is randomly selected from a distribution, and then run Monte-Carlo on that. But what you have written doesn't make sense. Where did these equations come from? Why the 46x16 size of zeta?
Shy
Shy el 27 de Jul. de 2020
I am running a similar system like that consisting of four ODEs, so the question is how to parse a matrix into the ode45 solver? Can you please provide me with your email so that I can email you on?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by