ODE with goniometric function

조회 수: 2 (최근 30일)
Radek Zenkel
Radek Zenkel 2018년 4월 10일
댓글: Star Strider 2018년 4월 11일
Hi, how can I solve and plot this ODE: 1*y''+23.25*(2.5*sin(x+1.5))*y'=0
there is my code:
eqn = '1*D2y+23.25*(2.5*sin(x+1.5))*D1y = 0';
inits = 'y(0)=0.7, Dy(0)=6.2';
y=dsolve(eqn,inits,'x')
ezplot(y, [-1 10])
Thank you so much

답변 (1개)

Star Strider
Star Strider 2018년 4월 10일
This works in R2018a, although it gives a ‘Warning’ about array inputs:
syms x y(x)
D1y = diff(y);
D2y = diff(D1y);
eqn = D2y+23.25*(2.5*sin(x+1.5))*D1y == 0;
inits = [y(0)==0.7, D1y(0)==6.2];
y=dsolve(eqn,inits)
Y = matlabFunction(y)
ezplot(Y, [-1 10])
This assumes that ‘y’ is a function of ‘x’. If both ‘x’ and ‘y’ are functions of another variable, we need to know.
  댓글 수: 2
Radek Zenkel
Radek Zenkel 2018년 4월 11일
I have R2015a and in this version it does not work :/
Error using symengine (line 59) The number of arguments in call of function 'int' is incorrect.
Error in sym/matlabFunction>mup2matcell (line 336) r = mup2mat(c{1});
Star Strider
Star Strider 2018년 4월 11일
In R2018a the matlabFunction call produces:
Y =
function_handle with value:
@(x)exp(cos(3.0./2.0).*(-4.65e2./8.0)).*integral(@(y)exp(cos(y+3.0./2.0).*(4.65e2./8.0)),0.0,x).*(3.1e1./5.0)+7.0./1.0e1
or, more conveniently:
Y = @(x) exp(cos(3.0./2.0).*(-4.65e2./8.0)).*integral(@(y)exp(cos(y+3.0./2.0).*(4.65e2./8.0)),0.0,x).*(3.1e1./5.0)+7.0./1.0e1;
however only this construction appears to work:
Y = @(x) exp(cos(3.0./2.0).*(-4.65e2./8.0)).*integral(@(y)exp(cos(y+3.0./2.0).*(4.65e2./8.0)),0.0,x,'ArrayValued',1).*(3.1e1./5.0)+7.0./1.0e1;
X = linspace(-1, 10);
Yv = arrayfun(Y, X);
figure
plot(X, Yv)
grid

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by