# How do I solve a second order non linear differential equation using matlab.

조회 수: 17 (최근 30일)
Patrick Guarente 2017년 9월 25일
답변: Lewis Fer 2021년 6월 10일
I have a fluid dynamics problem and I need to derive an equation for motion.
After applying Newtons second law to the system, and replaceing all the constants with A and B. My equation looks like this.
z'' + A(z')^2 = B
With A and B both being constants.
Initial conditions being that z(0)=0, and z'(0)=0
And I need to solve for z(t).
Thank you
##### 댓글 수: 4이전 댓글 2개 표시이전 댓글 2개 숨기기
James Tursa 2017년 9월 25일
편집: James Tursa 2017년 9월 25일
"... I need to find the equation for all time ..."
Are you looking for an analytical/symbolic solution? I thought that you simply wanted a numerical solution given your initial starting values.
Patrick Guarente 2017년 9월 25일
Yes the analytical solution in terms of A and B.

댓글을 달려면 로그인하십시오.

### 답변 (4개)

Teja Muppirala 2017년 9월 26일
syms z(t) t A B
zp = diff(z,t);
zpp = diff(z,t,2);
eqn = ( zpp + A*zp^2 == B );
cond = [z(0)==0, zp(0)==0];
zSol = dsolve(eqn,cond,'IgnoreAnalyticConstraints',true);
zSol = unique(simplify(zSol));
This gives 3 solutions:
zSol =
log((C15*sinh(A^(1/2)*B^(1/2)*(t + A*B^(1/2)*1i)))/B^(1/2))/A
log(-(C18*sinh(A^(3/2)*B*1i - A^(1/2)*B^(1/2)*t))/B^(1/2))/A
log(cosh(A^(1/2)*B^(1/2)*t))/A
The first two look weird, but are valid solutions involving complex-valued z. The 3rd solution is real, and that's probably the one that you are looking for.
##### 댓글 수: 0이전 댓글 -2개 표시이전 댓글 -2개 숨기기

댓글을 달려면 로그인하십시오.

Lewis Fer 2021년 6월 10일
Hello, I am having troubles solving a system of second order nonlinear equations with boundary conditions using MATALB
Here is the equations:
f''(t)=3*f(t)*g(t) -g(t)+5*t;
g''(t)=-4f(t)*g(t)+f(t)-7*t;
the boundary conditions are: f'(0)=0 et h'(o)=5;
g(0)=3 et h'(2)=h(2)
##### 댓글 수: 0이전 댓글 -2개 표시이전 댓글 -2개 숨기기

댓글을 달려면 로그인하십시오.

James Tursa 2017년 9월 25일
편집: James Tursa 2017년 9월 25일
Define a 2-element vector y:
y(1) = z
y(2) = z'
then solve your 2nd order ODE for the highest derivative:
z'' + A(z')^2 = B ==>
z'' = - A(z')^2 + B
then calculate the y element derivative equations, using this z derivative info:
d y(1) = d z = z' = y(2)
d y(2) = d z' = z'' = -A(z')^2 + B = -A*y(2) + B
So create a derivative function based on those two equations, using the function signature that you will find in the ode45 doc. Then call it using the outline provided in the example in the doc.
EDIT: SYMBOLIC SOLUTION
>> dsolve('D2z + A*(Dz)^2 = B')
ans =
C29 + (B^(1/2)*t)/A^(1/2)
C27 - (B^(1/2)*t)/A^(1/2)
log((exp(2*A^(3/2)*B^(1/2)*(C24 + t/A)) - 1)/(2*B^(1/2)*exp(A*(C16 + A^(1/2)*B^(1/2)*(C24 + t/A)))))/A
log((exp(2*A^(3/2)*B^(1/2)*(C20 - t/A)) - 1)/(2*B^(1/2)*exp(A*(C16 + A^(1/2)*B^(1/2)*(C20 - t/A)))))/A
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Patrick Guarente 2017년 9월 25일
I'm not sure where those two equations will be implemented.

댓글을 달려면 로그인하십시오.

Torsten 2017년 9월 26일
According to MATHEMATICA, the analytical solution is
z(x) = log(cosh(sqrt(A*B)*x))/A
Best wishes
Torsten.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by