Errors when using the function ODE 45
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
