Can you help me with this task?
Afficher commentaires plus anciens
x³y" + x²y' = 1 i have to write a code that solves this differential equetion? any hints or examples how to do it?
Réponses (2)
l l
le 16 Juin 2022
0 votes
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
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')
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
