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
madhan ravi 2018 年 11 月 11 日
編集済み: madhan ravi 2018 年 11 月 11 日

1 投票

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 件のコメント

Elina Makieva
Elina Makieva 2018 年 11 月 11 日
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
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
Elina Makieva
Elina Makieva 2018 年 11 月 11 日
Yes, and received such an error...
Elina Makieva
Elina Makieva 2018 年 11 月 11 日
編集済み: madhan ravi 2018 年 11 月 11 日
This is what I insert
madhan ravi's reply : the second picture in this comment is the file you should run by clicking the green button .
madhan ravi
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
Elina Makieva
Elina Makieva 2018 年 11 月 11 日
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?
madhan ravi
madhan ravi 2018 年 11 月 11 日
just copy my answer from tspan=[0 1]; till end and paste it in command window and press enter
Elina Makieva
Elina Makieva 2018 年 11 月 11 日
And again...
madhan ravi
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
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
Elina Makieva 2018 年 11 月 11 日
編集済み: madhan ravi 2018 年 11 月 11 日
oh,sorry
Elina Makieva
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
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.
see GIF to understand how it works .
madhan ravi
madhan ravi 2018 年 11 月 11 日
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
Elina Makieva
Elina Makieva 2018 年 11 月 11 日
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
madhan ravi
madhan ravi 2018 年 11 月 11 日
OMG :) I know but if you press enter you should get the result
Elina Makieva
Elina Makieva 2018 年 11 月 11 日
Ok, just a minute
Elina Makieva
Elina Makieva 2018 年 11 月 11 日
:))) I deleted all previous files, but... :))
Elina Makieva
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.
see common errors while calling a function which will make you understand how the function works.
Elina Makieva
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?
madhan ravi's reply : I don't know what a global phase portrait is, that's why I made this comment
Bruno Luong
Bruno Luong 2018 年 11 月 11 日
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
madhan ravi
madhan ravi 2018 年 11 月 11 日
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
Elina Makieva
Elina Makieva 2018 年 11 月 11 日
Thank you @Bruno! @Madhan could you please help me with my question about phase portrait? Or I should create new question?
madhan ravi
madhan ravi 2018 年 11 月 11 日
Please create a new question @Elina
Elina Makieva
Elina Makieva 2018 年 11 月 11 日
Thank you a lot!
madhan ravi
madhan ravi 2018 年 11 月 11 日
編集済み: madhan ravi 2018 年 11 月 11 日
Anytime :)
Elina Makieva
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 件)

カテゴリ

製品

質問済み:

2018 年 11 月 11 日

編集済み:

2018 年 11 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by