Can you help me with this task?
5 views (last 30 days)
Show older comments
x³y" + x²y' = 1 i have to write a code that solves this differential equetion? any hints or examples how to do it?
0 Comments
Answers (2)
l l
on 16 Jun 2022
You need to convert the n-th order ODE equation into a system of n first-order ODE equations. See https://www.mathworks.com/help/matlab/ref/ode45.html#bu3uj8b
0 Comments
Sam Chak
on 18 Jun 2022
As a beginner, maybe you can do something like this in just 3 simple steps:
- Write a system of first-order ODEs as anonymous functions.
- Solve ODEs using ode45 with the specified x range and initial condition.
- Plot the system response.
Simulation begins from
to
.
Initial condition is chosen as
to
.
% Step 1: create anonymous function handle
f1 = @(x, y) y(2); % y₁' = y₂
f2 = @(x, y) (1 - (x^2)*y(2))/x^3; % y₂' = (1 - x²·y₂)/x³, ... rearranged from x³·y" + x²·y' = 1
% Step 2: solve ODEs using ode45 solver
[x, y] = ode45(@(x, y) ([f1(x, y); f2(x, y)]), [1 10], [0 0]); % singularity occurs at x = 0
% Step 3: plot and labels
plot(x, y, 'linewidth', 1.5), grid on, xlabel('x'), ylabel('y'), title('y vs. x')
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!