Solving 4th order ode using ode45
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
How to solve the following 4th order ode using ode45 solver
댓글 수: 3
Are you sure ode45() is the one to use? Seems like a BVP problem.
...and aren't you missing one boundary-value?
@madhan - perhaps just as "easy" to use shooting method to find a solution that trails of towads flat at infinity?
Thank you. I will try with that method.
채택된 답변
Alan Stevens
2020년 9월 15일
Here's some coding that basically solves the equation. I've no idea what the value of k should really be, but the constants chosen give a consistent result. The choice of f'''(0) is based on the original equation with the other x=0 values plugged in; where f''(0) is a chosen to give a seemingly reasonable result!
k = -0.002;
xspan = [0 100];
d2fdx20 = -1;
F0 = [0 1 d2fdx20 (1-k*(d2fdx20^2))/(1-2*k)];
[x, F] = ode45(@rates, xspan, F0, [], k);
f = F(:,1);
dfdx = F(:,2);
plot(x, f, x, dfdx),grid
xlabel('x'), ylabel('f and dfdx')
legend('f','dfdx')
function dFdx = rates(x,F,k)
f = F(1);
dfdx = F(2);
d2fdx2 = F(3);
d3fdx3 = F(4);
if x==0
d4fdx4 = 0;
else
d4fdx4 = (d3fdx3 +f.*d2fdx2 - dfdx.^2 - 2*k*dfdx.*d3fdx3 + k*d2fdx2.^2)./(k*f);
end
dFdx = [dfdx; d2fdx2; d3fdx3; d4fdx4];
end
댓글 수: 23
In the above f'(x) actually goes to a small negative value, which gradually drags f down. If we assume the small negative value is a result of numerical inaccuracies, then by replacing
dfdx = F(2);
by
dfdx = max(F(2),0);
in function "rates", we get f tending to a constant.
Thank you. I have added a negative sign in d4fdx4 expression and taken positive value for k. It works well.
Hi Alan. when f(0)=1, how to take F0?
If f is a function, then just like that, if f is the output from your ODE, then it is an array where each element matches the function-values (f and its derivatives) at the values of x. Then you get "f(x=0)" as: F(1,1) if x(1) == 0.
Set the first element of F0 to 1.
Yes, first element of F0 is 1. What will be the fourth element?
Assuming that f''''(0) = 0, then use your ODE with f(0) = 1 and rearrange it to get f'''(0) in terms of f(0), f'(0), f''(0) and k. You will still have to make an assumption about f''(0) though (I'd be inclined to keep it at -1 initially).
Elayarani M
2020년 9월 17일
편집: Elayarani M
2020년 9월 17일
Is it correct to assume fourth derivative of f to zero at x=0. Will it not affect the result?
The expression for the fourth derivative is
d4fdx4 = (d3fdx3 +f.*d2fdx2 - dfdx.^2 - 2*k*dfdx.*d3fdx3 + k*d2fdx2.^2)./(k*f);
This has f in the denominator. When f(0) is zero, the only way of avoiding a singularity at x = 0 is to assume the derivative itself is zero. This isn't necessarily the case when f(0) = 1, so you could remove the part of the " if" statement that sets it to zero in this case.
Yes, I have removed that part for f(0)=1. Should i put f""(0)=0 for finding f'''(0) expression in F0 array? Is it correct to put that?
Yes if it leads to the numerator of d4fdx4 being zero; then it would be consistent at least.
Thank you Alan Stevens. I will try with that.
Elayarani M
2020년 9월 18일
편집: Elayarani M
2020년 9월 18일
For the case f(0)=1
If i put f''''(0)=0 for finding f'''(0) expression, am not getting the correct value. I tried with two assumptions but its not working correctly. I dont know how to take f'''(0) expression in F0 array. Can anyone help?
What's the value of k you are using?
For a first-order ODE you need to specify one boundary-condition, for a second-order ODE you need to specify 2 boundary conditions (e.g. with an equation of motion you need to specify the initial position and velocity). For an n-th order ODE you have to specify n boundary conditions. You have a 4th-order ODE with 3 specified boundary-conditions (two initial, for f(0) and f'(0) and one end-condition for f'(inf)). One way to handle this is to view this problem as a parameter-estimation-problem where you have to estimate the initial conditions for f'' and f''' that satisfies your end-condition, this method is known as the shooting method. If you use this you have to make a search for the values of f''(0) and f'''(0) that gives you a value of f'(inf) that fits.
k=-1; d4fdx4 = -(d3fdx3 +f.*d2fdx2 - dfdx.^2 - 2*k*dfdx.*d3fdx3 + k*d2fdx2.^2)./(k*f); When f(0)=0, f''''(0) term vanishes in f'''(0) expression but when f(0)=1,f''''(0) term exists. I dont know how to handle that.
Hi Bjorn Gustavsson. Using shooting method, when i make two initial guesses for the unknowns f''(0) and f'''(0) and make search for the values of f''(0) and f'''(0) that satisfies f'(inf)=0, it gives some value but not the correct value.
Do you get a solution that satisfies the ODE and your given initial conditions (f(0)=0, and f'(0)=1), and the end-condition?
If you need to get to infinity in a more proper sense you might have to make a variable-substitution, something like
t = tan(theta)
and then transform your ODE too.
Yes, I get some solution that satisfies the given conditions. I will try with variable-substitution.
In the case that you get a solution that matches your boundary-conditions and satisfies your ODE why is that not good enough?
The solution was not correct when compared with analytic solution.
Did the numerical solution differ by much? If not then perhaps only numerical deviations? Since you have a non-linear ODE there might be many solutions (right?), have you gotten all analytically? If not then the numerical solution might be one of the other valid solutions.
Thank you Bjorn Gustavsson. First I will try to get all analytic solution and then cross check with the numerical solution.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
