Hi everybody
I am trying to solve a couples ODE system, I wrote the code below but it has an error. I changed the code several times but it didnt work. How can I fix it???
thank you.

3 Commenti

Rik
Rik il 25 Gen 2021
If you had pasted your code as code, others can actually run it.
function Idot=motor(t,Z)
Zdot=zeros(2,1);
Rs=0.1;
Ls=0.5;
W=314;
B=0;
time=0:0.1:5;
% va=100*sin(W*t-B);
% vb=100*sin(W*t-B-(pi/2));
% Zdot(1)=(-Rs*Z(1)+100*sin(W*time-B))/Ls;
% Zdot(2)=(-Rs*Z(2)+100*sin(W*time-B-(pi/2)))/Ls;
Zdot(1)=(-Rs*Z(1)+100*sin(W))/Ls;
Zdot(2)=(-Rs*Z(2)+100*sin(W-(pi/2)))/Ls;
end
clc
clear
t=[0,5];
x0=0;
xdot0=5;
z0=[x0,xdot0];
[T,Z]=ode45(motor,t,z0)
plot(T,Z)
function Idot=motor(t,Z)
output should be Zdot not Idot

Accedi per commentare.

 Risposta accettata

Alan Stevens
Alan Stevens il 25 Gen 2021
Modificato: Rik il 25 Gen 2021
More like this:
t=0:0.1:5;
x0=0;
xdot0=5;
z0=[x0,xdot0];
[T,Z]=ode45(@motor,t,z0); % Note @motor, not just motor.
plot(T,Z)
function Zdot=motor(t,Z)
Zdot=zeros(2,1);
Rs=0.1;
Ls=0.5;
W=314;
%B=0;
Zdot(1)=(-Rs*Z(1)+100*sin(W*t))/Ls;
Zdot(2)=(-Rs*Z(2)+100*sin(W*t-(pi/2)))/Ls;
end
(code executed by @Rik)

2 Commenti

Output argument "Idot" (and maybe others) not assigned during call to "motor".
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 motor2 (line 9)
[T,Z]=ode45(@motor,t,z0)
Still having Error
Alan Stevens
Alan Stevens il 25 Gen 2021
I corrected the other errors! Copy and paste the coding. Look carefully at the other lines.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by