2nd order non linear ODE
Mostrar comentarios más antiguos
I cannot figure out how to solve the folowing non linear eigen value ODE numerically on MATLAB.
I know the value of the second term, g as well. My boundary conditions are
and
. I know how to solve it by hand but MATLAB is a different story for me. Please help out.
Respuestas (1)
Star Strider
el 18 de Mzo. de 2021
0 votos
‘Do I have to convert it into system of 2 first order equation?’
Yes.
The Symbolic Math Toolbox can make that easier. Use the odeToVectorField and matlabFunction functions to create it as an anonymous function.
Also, since this is a boundary value problem, bvp4c or similar functions may be most appropriate. (I have no idea what ‘E’ and ω are, however using this approach and using random values for those and guessing 9.81 for ‘g’, I got it to work with bvp4c.)
I would post my solution, however I would not want to deprive you of the experience of discovering how to do all this for yourself.
15 comentarios
Ahsan Mujtaba
el 23 de Mzo. de 2021
Editada: Ahsan Mujtaba
el 23 de Mzo. de 2021
Star Strider
el 24 de Mzo. de 2021
With zero initial conditions for both differential equations, the integrated result will be identically zero.
Ityy is possible to get a non-zero result with non-zero initial conditions:
yInit=[0 0]+eps;
That aside, something like this could do what you want:
syms y(x)
a=0.4871;%value of E/w
g=10;
eqn=diff(y,2)==(a-(sin(sqrt(g)*x)/g))*y;%converted equation to x and y for ease
v = odeToVectorField(eqn)
M = matlabFunction(v,'vars',{'x','Y'})
interval=[-pi/2 pi/2];%sqrt(g)x interval
interval = linspace(-pi/2,pi/2,10000)*sqrt(g);
yInit=[0 0]+eps;
[x,y] = ode45(M,interval,yInit);
xValues=linspace(-pi/2,pi/2,10000)*sqrt(g);
yValues = y(:,1);
plot(xValues,yValues)
Experiment to get the result that you want.
Ahsan Mujtaba
el 24 de Mzo. de 2021
Star Strider
el 24 de Mzo. de 2021
I forgot about it being a boundary value problem. I solved it as such a few days ago. Use bvp4c to integrate it. I used the symbolic code similar to what you are using to create the anonymous function for the differential equation system, then hand-coded the rest.
If you have problems, I can use my solution to guide you through solving it. The plot looks like a parabola (or part of a sine curve).
Ahsan Mujtaba
el 24 de Mzo. de 2021
Star Strider
el 24 de Mzo. de 2021
My pleasure!
See the bvp4c documentation that I linked to. It has everything you need to solve it (and is what I used, since I do not code boundary value problems very often, and neded to refer to it).
Ahsan Mujtaba
el 25 de Mzo. de 2021
Ahsan Mujtaba
el 25 de Mzo. de 2021
Star Strider
el 25 de Mzo. de 2021
I selected only the first row of the solution to plot, so only
, with this result —
, with this result — 
The second row
simply plots a straight line with a negative slope, so I am not plotting it.
I am using my own XTickLabel strings for clarity.
Ahsan Mujtaba
el 25 de Mzo. de 2021
Star Strider
el 25 de Mzo. de 2021
You must have posted your code while I was posting my plot. I did not see it before.
There are only two boundary conditions. You are coding three of them. Also, when I try to run your code, the first boundary condition throws this error:
Array indices must be positive integers or logical values.
Error in ... mat4bc (line ##)
res = [ya(-4.96)
Please understand that these are actually subscripts into the differential equation function variables, not arguments. You need to re-code the boundary conditions.
I coded only 25 points in the initial mesh. Fewer than 1000 of them may be desirable, unless your code throws an error about a singular Jacobian (that I doubt it will), in which situation more points will be necessary. The bvp4c function will tell you if it needs a larger mesh.
Ahsan Mujtaba
el 25 de Mzo. de 2021
Star Strider
el 25 de Mzo. de 2021
The documentation for bvp4c describes exactly how to code them.
Ahsan Mujtaba
el 25 de Mzo. de 2021
Star Strider
el 25 de Mzo. de 2021
I am not certain what it is supposed to look like, or if my plot is correct. (It would appear to be correct, however I am not certain it is.)
I used a different ‘guess’, and when I use the same in your code, I get essentially the same result I got in mine, although your ‘dydx’ is different from the function I used, that being the result of the matlabFunction call in my code. I also used only 25 points in ‘xmesh’, and that made for a smoother plotted result.
UPDATE — I did not previously realise it, however Mathieu’s equation is actually in the MATLAB documentation. (I just now discovered that in an Interweb search.) See Solve BVP with Unknown Parameter for details. It woulld appear that my result is correct, given that the parameters may not be the same (I have not checked them, since it is late here, and the end of my day.).
I find that comforting!
Categorías
Más información sobre Numerical Integration and Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
