How to parse a Matrix ODE45. Getting simulation error

5 Ansichten (letzte 30 Tage)
Shy
Shy am 27 Jul. 2020
Kommentiert: Shy am 27 Jul. 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 Kommentare
James Tursa
James Tursa am 27 Jul. 2020
Bearbeitet: James Tursa am 27 Jul. 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 am 27 Jul. 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?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by