How to parse a Matrix ODE45. Getting simulation error
이전 댓글 표시
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
James Tursa
2020년 7월 27일
What is the ODE you are trying to solve, and what is the purpose of zeta?
Shy
2020년 7월 27일
James Tursa
2020년 7월 27일
I mean, what is the differential equation you are trying to solve? Post the equation for us to see, with a definition of zeta. Are you trying to run a Monte-Carlo simulation with various random values of zeta?
Shy
2020년 7월 27일
James Tursa
2020년 7월 27일
편집: James Tursa
2020년 7월 27일
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
2020년 7월 27일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
