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

Rik
Rik 2021년 1월 25일
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

댓글을 달려면 로그인하십시오.

 채택된 답변

Alan Stevens
Alan Stevens 2021년 1월 25일
편집: Rik 2021년 1월 25일

0 개 추천

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

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 2021년 1월 25일
I corrected the other errors! Copy and paste the coding. Look carefully at the other lines.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Community Treasure Hunt

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

Start Hunting!

Translated by