how to get rid of error which says too many output arguments

17 Ansichten (letzte 30 Tage)
naveed bashir
naveed bashir am 10 Dez. 2019
Beantwortet: Star Strider am 10 Dez. 2019
hi,
i want to solve the equation d^2x/dt^2= f(-2*x3 + x2) which is for 3 harmonic oscillators.In my editor i wrote the following;
function test3(t,x)
xdot(1)=x(2);
xdot(2)= 10*(-2*x3 + x2);
xdot=xdot';
end
and then i executed the command:
[t,x]=ode45('test3', [0 5], [2 3]);
and the error i get is " too many output arguments" which i don't know how to omit. How can i get rid of this error? Kindly if someone could help me figure it out i would be grateful. Thanks

Antworten (1)

Star Strider
Star Strider am 10 Dez. 2019
The ‘test3’ function needs to be:
function xdot = test3(t,x)
xdot(1)=x(2);
xdot(2)= 10*(-2*x3 + x2);
xdot=xdot';
end
and the ode45 call needs to be:
[t,x]=ode45(@test3, [0 5], [2 3]);
That should work.

Kategorien

Mehr zu Scope Variables and Generate Names finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by