How to solve and graph a second order nonlinear differential equation?

8 views (last 30 days)
Hi everyone,
I'm pretty new to matlab, and have been trying to use bvp4c and ode45 functions to try to solve and graph a second order non linear differential equation, but I'm not sure these are the right ones to use or where I'm going wrong with them. I think the main issue is that, with the bvp4c function, it may require boundary conditions at two locations to be = 0, while my graph should look more like a logarithmic graph.
My equation takes the following form:
y'' + f(y)y' = g(y)
Over the interval 0 < x < 10, with y(10) = A, where A is a constant. Any advice on the right approach to take would be appreciated!
  1 Comment
Torsten
Torsten on 19 Apr 2022
You need two boundary conditions to solve your equation.
If you impose both conditions at the same end of the integration interval, use ode45or ode15s.
If you impose the two conditions at both ends of the integration interval, use bvp4c.

Sign in to comment.

Answers (2)

Sam Chak
Sam Chak on 19 Apr 2022
Not exactly sure what you are tring to solve, but this worth a try, although it may not be the exact solution that you are seeking. However, if is known and is the manipulated variable, then we can design
.
In the following example, is assumed as a bounded nonlinear function, where as well.
% Desired output at y(10)
A = 1
% ODE
f = @(t, x) [x(2); ...
sin(x(1))*x(2) - 2*x(2) - (x(1) - A) - sin(x(1))*x(2)];
init = [0 0]; % initial condition
tspan = [0 10];
[t, x] = ode45(f, tspan, init);
plot(t, x(:,1))
x(end,1)
Try plotting the output and see if that is desired. You can change the initial value and desired output for A as well.

Nour
Nour on 10 Jan 2024
% Desired output at y(10) A = 1
% ODE f = @(t, x) [x(2); ... sin(x(1))*x(2) - 2*x(2) - (x(1) - A) - sin(x(1))*x(2)];
init = [0 0]; % initial condition
tspan = [0 10];
[t, x] = ode45(f, tspan, init);
plot(t, x(:,1)) x(end,1)

Tags

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!