Errors when using the function ODE 45
显示 更早的评论
Hello! Please help me when using ODE 45! I receive errors:
1) Not enough input arguments. Error in peFun (line 5) eta=ALPHA(1);
2) Error in odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
3) Undefined function or variable 'vPUR'
function fval=peFun(t,ALPHA)
tspan=[0 1];
% Get variables
eta=ALPHA(1);
r=ALPHA(2);
beta=ALPHA(3);
alpha=ALPHA(4);
xP=ALPHA(5);
yP=ALPHA(6);
xE=ALPHA(7);
yE=ALPHA(8);
% Constants
vER=3;
vPUR=5;
a=1;
% Describing dALPHA/dt
fval=zeros(8,1);
fval(1,1)=(-vPUR*SIN(beta)+vER*SIN(alpha))/r;
fval(2,1)=vER*COS(alpha)-vPUR*COS(beta);
fval(3,1)=(a/r)*(vER*SIN(alpha)-vPUR*SIN(beta));
fval(4,1)=(-vER*SIN(alpha)+vPER*SIN(beta))/r;
fval(5,1)=vPUR*COS(eta+beta);
fval(6,1)=vPUR*SIN(eta+beta);
fval(7,1)=vER*COS(eta+alpha);
fval(8,1)=vER*SIN(eta+alpha);
% To run P-E system
%%Initialization
eta0=pi/4;
r0=sqrt(2);
beta0=0;
alpha0=pi/4;
xP0=0;
yP0=0;
xE0=1;
yE0=1;
ALPHA0=[eta0;r0;beta0;alpha0;xP0;yP0;xE0;yE0];
%Solve using ODE45
[tSol,ALPHASol]=ode45(@peFun,tspan,ALPHA0);
%Plot the results
plot(tSol,ALPHASol);
Thank you!
采纳的回答
madhan ravi
2018-11-11
编辑:madhan ravi
2018-11-11
tspan=[0 1];
% To run P-E system
%%Initialization
eta0=pi/4;
r0=sqrt(2);
beta0=0;
alpha0=pi/4;
xP0=0;
yP0=0;
xE0=1;
yE0=1;
ALPHA0=[eta0;r0;beta0;alpha0;xP0;yP0;xE0;yE0];
[tSol,ALPHASol]=ode45(@peFun,tspan,ALPHA0); %function calling before function definition
plot(tSol,ALPHASol);
function fval=peFun(t,ALPHA)
% Get variables
eta=ALPHA(1);
r=ALPHA(2);
beta=ALPHA(3);
alpha=ALPHA(4);
xP=ALPHA(5);
yP=ALPHA(6);
xE=ALPHA(7);
yE=ALPHA(8);
% Constants
vER=3;
vPUR=5;
a=1;
% Describing dALPHA/dt
fval=zeros(8,1);
fval(1,1)=(-vPUR*sin(beta)+vER*sin(alpha))/r;
fval(2,1)=vER*cos(alpha)-vPUR*cos(beta);
fval(3,1)=(a/r)*(vER*sin(alpha)-vPUR*sin(beta));
fval(4,1)=(-vER*sin(alpha)+vER*sin(beta))/r;
fval(5,1)=vPUR*cos(eta+beta);
fval(6,1)=vPUR*sin(eta+beta);
fval(7,1)=vER*cos(eta+alpha);
fval(8,1)=vER*sin(eta+alpha);
end
27 个评论
I got another problem: >> peFun Not enough input arguments.
Error in peFun (line 3) eta=ALPHA(1);
I will be very grateful if you kindly help me!
madhan ravi
2018-11-11
编辑:madhan ravi
2018-11-11
I got the graph did you try my answer? see the attached screenshot of the graph in my answer
Yes, and received such an error...
Elina Makieva
2018-11-11
编辑:madhan ravi
2018-11-11
madhan ravi
2018-11-11
编辑:madhan ravi
2018-11-11
Just copy my answer and save it in a script file and click green button
Sorry for stupid questions, I`ve just started learning MATLAB. should I insert your answer in two different windows as it was before or how?
just copy my answer from tspan=[0 1]; till end and paste it in command window and press enter
And again...
madhan ravi
2018-11-11
编辑:madhan ravi
2018-11-11
paste the code here what you tried ,and delete the two files which you saved before
Elina Makieva
2018-11-11
编辑:madhan ravi
2018-11-11
tspan=[0 1];
% To run P-E system
%%Initialization
eta0=pi/4;
r0=sqrt(2);
beta0=0;
alpha0=pi/4;
xP0=0;
yP0=0;
xE0=1;
yE0=1;
ALPHA0=[eta0;r0;beta0;alpha0;xP0;yP0;xE0;yE0];
[tSol,ALPHASol]=ode45(@peFun,tspan,ALPHA0); %function calling before function definition
plot(tSol,ALPHASol);
function fval=peFun(t,ALPHA)
% Get variables
eta=ALPHA(1);
r=ALPHA(2);
beta=ALPHA(3);
alpha=ALPHA(4);
xP=ALPHA(5);
yP=ALPHA(6);
xE=ALPHA(7);
yE=ALPHA(8);
% Constants
vER=3;
vPUR=5;
a=1;
% Describing dALPHA/dt
fval=zeros(8,1);
fval(1,1)=(-vPUR*sin(beta)+vER*sin(alpha))/r;
fval(2,1)=vER*cos(alpha)-vPUR*cos(beta);
fval(3,1)=(a/r)*(vER*sin(alpha)-vPUR*sin(beta));
fval(4,1)=(-vER*sin(alpha)+vER*sin(beta))/r;
fval(5,1)=vPUR*cos(eta+beta);
fval(6,1)=vPUR*sin(eta+beta);
fval(7,1)=vER*cos(eta+alpha);
fval(8,1)=vER*sin(eta+alpha);
end
Elina Makieva
2018-11-11
编辑:madhan ravi
2018-11-11
oh,sorry
Elina Makieva
2018-11-11
编辑:madhan ravi
2018-11-11
tspan=[0 1];
% To run P-E system
%%Initialization
eta0=pi/4;
r0=sqrt(2);
beta0=0;
alpha0=pi/4;
xP0=0;
yP0=0;
xE0=1;
yE0=1;
ALPHA0=[eta0;r0;beta0;alpha0;xP0;yP0;xE0;yE0];
[tSol,ALPHASol]=ode45(@peFun,tspan,ALPHA0); %function calling before function definition
plot(tSol,ALPHASol);
function fval=peFun(t,ALPHA)
% Get variables
eta=ALPHA(1);
r=ALPHA(2);
beta=ALPHA(3);
alpha=ALPHA(4);
xP=ALPHA(5);
yP=ALPHA(6);
xE=ALPHA(7);
yE=ALPHA(8);
% Constants
vER=3;
vPUR=5;
a=1;
% Describing dALPHA/dt
fval=zeros(8,1);
fval(1,1)=(-vPUR*sin(beta)+vER*sin(alpha))/r;
fval(2,1)=vER*cos(alpha)-vPUR*cos(beta);
fval(3,1)=(a/r)*(vER*sin(alpha)-vPUR*sin(beta));
fval(4,1)=(-vER*sin(alpha)+vER*sin(beta))/r;
fval(5,1)=vPUR*cos(eta+beta);
fval(6,1)=vPUR*sin(eta+beta);
fval(7,1)=vER*cos(eta+alpha);
fval(8,1)=vER*sin(eta+alpha);
end
Elina Makieva
2018-11-11
编辑:madhan ravi
2018-11-11
I can`t insert it in a right formating
madhan ravi's reply: select the whole code and press the code button {} to format your code correctly.
just delete your files peFun.m and runpeFun.m
put clear all at the very beginning and paste the code again in command window and try again
I just copy your answer and paste in command window and press enter because there is not green button when I work with command window
OMG :) I know but if you press enter you should get the result
Ok, just a minute
:))) I deleted all previous files, but... :))
Elina Makieva
2018-11-11
编辑:madhan ravi
2018-11-11
OMG!!!IT WORKS!!! :)))) THANK YOU A LOT!!!!!! Could you please tell me, why, when I was doing it in two different windows, I received errors? And what was the initial problem, so I would not repeat it again?
madhan ravi's reply: your initial problem was you did everything correctly but you click run button in the function file(it isn't wrong to do that) but in your case it was because your function required inputs that had to be passed to evaluate those equations.
Elina Makieva
2018-11-11
编辑:madhan ravi
2018-11-11
Could you please tell, what function should I insert to receive global phase portrait like that?
when I was doing it in two different windows, I received errors?
function should be put in an mfile with right name in an accessible path or in some recent MATLAB release in the bottom of the script Here is the doc
Thank you @Bruno , @Elina just copy my answer and paste in a new script and save it and make sure to accept the answer since it answered your question
Thank you @Bruno! @Madhan could you please help me with my question about phase portrait? Or I should create new question?
Please create a new question @Elina
Thank you a lot!
madhan ravi
2018-11-11
编辑:madhan ravi
2018-11-11
Anytime :)
Elina Makieva
2018-11-11
编辑:madhan ravi
2018-11-11
I will really appreciate if you could help me with phase portrait https://www.mathworks.com/matlabcentral/answers/429206-errors-when-using-ode-45-phase-portraits
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
产品
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
