2-order linear differential equation with paramaters

1 次查看(过去 30 天)
I have to solve the following differential equation with parameters but I don't know how to declare the parameters. The differential equation is the following: diff(y,x,2)x+diff(y,x)(2k+1-2x^2)+y(E-2k-2)x == 0 where E and k are paramaters. Any help?
This code doesn't work because the constants E and k are not defined.
syms y(x)
ode = x*diff(y,x,2)+(1+2*k-2*x^2)*diff(y,x)+(E-2*(1+k))*y*x == 0;
ySol(x) = dsolve(ode);

回答(2 个)

Shoresh Shokoohi
Shoresh Shokoohi 2023-9-8
To solve the given differential equation with parameters E and k in MATLAB, you need to declare these parameters as symbolic variables using the syms function. Here's how you can modify your code to define E and k as symbolic variables:
% Define symbolic variables E and k
syms E k
% Define the function y(x) as a symbolic function
syms y(x)
% Define the differential equation with the parameters E and k
ode = x*diff(y,x,2) + (1 + 2*k - 2*x^2)*diff(y,x) + (E - 2*(1+k))*y*x == 0;
% Solve the differential equation
ySol(x) = dsolve(ode);
With these modifications, you've declared E and k as symbolic variables, and you can now solve the differential equation with respect to these parameters using the dsolve function.
  2 个评论
John D'Errico
John D'Errico 2023-9-8
编辑:John D'Errico 2023-9-8
+1 of course. I would add only that because these parameters are essentially unknowns, you cannot use a numerical solver like ODE45. Only a tool like dsolve can now apply. This should be no problem of course, since you wanted to use dsolve in the first place. But there will then always be someone down the line hoping to use ODE45.
Antonino Roccaforte
编辑:Antonino Roccaforte 2023-9-8
I tried to compile the code but in this way there is no output! How is it possible? The solution should be a linear combination of confluent hypergeometric functions...

请先登录,再进行评论。


Sam Chak
Sam Chak 2023-9-9
I'm unfamiliar with your ODE, but I tested it with dsolve, and there are some results, and one of them returns with the Confluent hypergeometric Kummer U function. By the way, I'm just curious: How does your ODE describe the physical real-world phenomenon?
syms t x y(x) E k
S1 = dsolve(x^1*diff(y,2) + (2*k + 1 - 2*x^2)*diff(y) + (E - 2*(1 + k))*x*y)
S1 = 
S2 = dsolve(x^3*diff(y,2) + (2*k + 1 - 2*x^2)*diff(y) + (E - 2*(1 + k))*x*y)
S2 = 

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by