ODE with goniometric function

2 views (last 30 days)
Radek Zenkel
Radek Zenkel on 10 Apr 2018
Commented: Star Strider on 11 Apr 2018
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

Answers (1)

Star Strider
Star Strider on 10 Apr 2018
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 Comments
Radek Zenkel
Radek Zenkel on 11 Apr 2018
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 on 11 Apr 2018
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

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!