HELP: 'Error: Function definitions are not permitted in this context.'

3 次查看(过去 30 天)
I'm new to matlab just for you to know.
I'm getting this error on this function:|
function [dydt]=deriv(t,y,a,b,u,df,dr,Fn)
dydt=zeros(2,1);
alphaf=(y(2)+a*y(1))/u-df; % Slip Angle Front [rad]
alphar=(y(2)-b*y(1))/u-dr; % Slip Angle Rear [rad]
tire_model(niu,Calpha,alphaf,alphar,Fn) % Lateral Forces [N]
dydt(1)= (1/Izz)*(Fyf*a-Fyr*b); % Yaw Acelaration
dydt(2)= (1/M)*(Fyf+Fyr)-u*y(1); % Lateral Acelaration
end
a,b,u,df,dr,Fn are defined in the main script, I noticed that if I define them inside this function it works, but that's not what I pretend.
Thanks in advance

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-11-15
编辑:Azzi Abdelmalek 2013-11-15
If a,b,u,df,dr and Fn are used by your function, you need to define them inside your function, or define them as input arguments.
  2 个评论
snrlax
snrlax 2013-11-15
Yes, they are. How do I define them as input arguments? I though it was enough putting them like this:
function [dydt]=deriv(t,y,a,b,u,df,dr,Fn)
I don't want to define them inside this function file, that's why.
Azzi Abdelmalek
Azzi Abdelmalek 2013-11-15
When you call the function, with ode45 for example:
[t,y]=ode45(@(t,y),deriv(t,y,a,b,u,df,dr,Fn),tspan,IC)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by