How to calculate differential equation with trigonometric function?
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How can I solve this differential equation using matlab? The answer can be in analytical, symbolic or numerical solution form. This is what I have done:
syms y(x)
ff=1+((2/y)*x+(x^2)*(y^2)*cos(y))*diff(y,x)==0;
y(x)=dsolve(ff)
And it shows y(x) = [empty sym], which is not a proper answer that I was requires to get. Also, I've tried using other solution methods:
f=@(x,y) ((2/y)*x+(x^2)*(y^2)*cos(y))*diff(y,x)==0;
[x,y]=ode45(@(x,y),f,[0 2],1);
plot(x,y)
But this shows invalid expression error and I don't know where the problem is.
0 Kommentare
Akzeptierte Antwort
KSSV
am 19 Mai 2022
f = @(x,y) -1./((2./y).*x+x.^2*y.^2.*cos(y)) ;
xspan = [0.1 2] ;
x0 = 1 ;
[x,y] = ode45(f, xspan, x0);
plot(x,y)
0 Kommentare
Weitere Antworten (1)
Sam Chak
am 19 Mai 2022
With the given ODE
function dydx = odefcn(x, y)
fcn = 2*x/y + (x^2)*(y^2)*cos(y);
dydx = - 1/fcn;
end
you can run the ode45 solver and plot the output. Note that or else singularity occurs.
h = 1e-4;
xspan = 0.1:h:10; % simulation x-range
init = 1;
[x, y] = ode45(@(x, y) odefcn(x, y), xspan, init);
plot(x, y, 'linewidth', 1.5)
grid on
xlabel({'$x$'}, 'Interpreter', 'latex')
ylabel({'$y$'}, 'Interpreter', 'latex')
title('System response')
0 Kommentare
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!