2-order linear differential equation with paramaters

1 view (last 30 days)
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);

Answers (2)

Shoresh Shokoohi
Shoresh Shokoohi on 8 Sep 2023
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 Comments
John D'Errico
John D'Errico on 8 Sep 2023
Edited: John D'Errico on 8 Sep 2023
+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 on 8 Sep 2023
Edited: Antonino Roccaforte on 8 Sep 2023
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...

Sign in to comment.


Sam Chak
Sam Chak on 9 Sep 2023
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 = 

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!