How to parse a Matrix ODE45. Getting simulation error
3 views (last 30 days)
Show older comments
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 Comments
James Tursa
on 27 Jul 2020
Edited: James Tursa
on 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?
Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!