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 件のコメント
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
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
2018 年 11 月 11 日
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
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
2018 年 11 月 11 日
just copy my answer from tspan=[0 1]; till end and paste it in command window and press enter
Elina Makieva
2018 年 11 月 11 日
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.
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
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
2018 年 11 月 11 日
OMG :) I know but if you press enter you should get the result
Elina Makieva
2018 年 11 月 11 日
Ok, just a minute
Elina Makieva
2018 年 11 月 11 日
:))) 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?
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
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
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
2018 年 11 月 11 日
Please create a new question @Elina
Elina Makieva
2018 年 11 月 11 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
