ODE with goniometric function
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!