please help me ode45 problem undefined argument
Mostrar comentarios más antiguos
i can't speak english well I want ode45 matlab plot
if true
% code
end
//this is fun.mfile
function xdot=fun(t,x);
xdot=zeros(2,1);
m=1400;
jw=0.65;
rw=0.31;
fz=3560;
cd=0.5;
p=1.202;
a=1.95;
bw=0;
fw=0;
nw=4;
g=9.81;
uw=0;
angle=0;
te=0;
tb=1;
if true
% code
end
lambda=(x(2)-x(1))/x(1);
//this is interaction formula
mu=5*lambda^3+2*lambda^+2*lambda^1+3;
//this is interaction formula
fx=mu*fz;
//this is interaction formula
xdot(1)=(-0.5*p*cd*a*(x(1)+uw)^2-f*m*g*cos(angle)-m*g*sin(angle)+nw*fx)/m/rw;
xdot(2)=(te-tb-rw*fx-tw*x(2))/jw;
[t1,x1]=ode45('fun',[0 1],20); [t2,x2]=ode45('fun',[0 1],20); plot(t1,x1,'-',t2,x2,'+') grid; xlabel('time');
but error undefined argument x..... why>?>>
1 comentario
Azzi Abdelmalek
el 8 de Nov. de 2013
If you want to comment your code, do not add
//this is interaction formula
Use instead
%this is interaction formula
Respuestas (1)
Azzi Abdelmalek
el 8 de Nov. de 2013
Editada: Azzi Abdelmalek
el 8 de Nov. de 2013
Save this function as fun.m and do not forget to add the missing values of t and tw
function xdot=fun(t,x);
tw=?
f=?
xdot=zeros(2,1);
m=1400;
jw=0.65;
rw=0.31;
fz=3560;
cd=0.5;
p=1.202;
a=1.95;
bw=0;
fw=0;
nw=4;
g=9.81;
uw=0;
angle=0;
te=0;
tb=1;
lambda=(x(2)-x(1))/x(1);
mu=5*lambda^3+2*lambda^+2*lambda^1+3;
fx=mu*fz;
xdot(1)=(-0.5*p*cd*a*(x(1)+uw)^2-f*m*g*cos(angle)-m*g*sin(angle)+nw*fx)/m/rw;
xdot(2)=(te-tb-rw*fx-tw*x(2))/jw;
Then in another m file or in Matlab windows command
[t1,x1]=ode45('fun1',[0 1],[20;0]); % the initial conditions should be 2x1 size
[t2,x2]=ode45('fun1',[0 1],[20;0]);
plot(t1,x1)
plot(t2,x2)
7 comentarios
Azzi Abdelmalek
el 8 de Nov. de 2013
Editada: Azzi Abdelmalek
el 8 de Nov. de 2013
Kim commented
I did your answer
but it have four error i don't underatand error's mean
>> Untitled2
Error using feval
Undefined function 'fun1' for input arguments of type 'double'.
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in Untitled2 (line 1)
[t1,x1]=ode45('fun1',[0 1],[20;0]); % the initial conditions should be 2x1 size
Azzi Abdelmalek
el 8 de Nov. de 2013
Editada: Azzi Abdelmalek
el 8 de Nov. de 2013
In the function correct this
function xdot=fun(t,x); % fun instead of fun1
and call your function
[t1,x1]=ode45('fun',[0 1],[20;0]); % the initial conditions should be 2x1 size
[t2,x2]=ode45('fun',[0 1],[20;0]);
plot(t1,x1)
plot(t2,x2)
kim
el 8 de Nov. de 2013
Azzi Abdelmalek
el 8 de Nov. de 2013
Please, to add a comment, click on [comment on this answer]
Azzi Abdelmalek
el 8 de Nov. de 2013
Editada: Azzi Abdelmalek
el 8 de Nov. de 2013
[Kim commented]
yes i know thankyou but.. same error. Undefined function or variable 'p'.
Error in fun (line 2)
fv(1,1)=[-0.5*p*cd*a(x1+uw).^2-f*m*g*cos(angle)-m*g*sin(angle)+nw*fx]/(rw*m);
Error in odearguments (line 88) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 114) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in Untitled2 (line 1)
[t1,x1]=ode45('fun',[0 1],[20;0]); % the initial conditions should be 2x1 size
Azzi Abdelmalek
el 8 de Nov. de 2013
Editada: Azzi Abdelmalek
el 8 de Nov. de 2013
What is this ?
fv(1,1)=[-0.5*p*cd*a(x1+uw).^2-f*m*g*cos(angle)-m*g*sin(angle)+nw*fx]/(rw*m);
It does not appear in your question
kim
el 8 de Nov. de 2013
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!