Hi, I tried solving a system for:
if true
% code
end
eqns = h^2*[diff(y,t)+2*i*g*y+g^2==0, diff(z,t)==y];
sol = dsolve(eqns)
and get:
>> Solve_Systems_of_ODE
h = 2 g =
5
sol =
struct with fields:
z: [1×1 sym]
y: [1×1 sym]
what does this result mean really?
Thanks

10 Comments

John D'Errico
John D'Errico on 8 Dec 2017
Edited: John D'Errico on 8 Dec 2017
I'm a bit mystified. Are you asking someone to explain ordinary differential equations? That usually takes place in an entire semester long course at the undergraduate level.
y is dz/dt, so this is a second order ODE. Someone has converted that 2nd order ODE into a system of first order ODEs.
So what is it that you don't follow?
I am trying to know what the output means John, it has no solution as it stands.
z and y will be functions of t. They are the solution to the differential equation posed, IF it has a solution. As I said, the way it was defined, you have created y as dz/dt, so a second order ODE.
But I am still mystified as to your question "What does the output mean?" z and y will be the solution to the ODE system posed.
Did you look at sol.z and sol.y?
Hi John, no I didn't. I haven't tried this approach before, so my command ended there without sol.z. Checking it now. Thanks
Hi again John, I take I am unsure on which solver I should use. As I wrote just above to Birdman, I used some solver 3 months ago I cannot find again (in MATLAB). Then, I got that simple soln. to the initial condition problem given (without y''(0)= Dsin(x). I am checking out:
https://se.mathworks.com/help/symbolic/ordinary-differential-equations.html
In order to find the suitable solver.
Hi John, I looked up and found one of the solvers I used:
if true
% code
end
syms a h Y(theta) g
eqn = h^2*diff(Y,theta, 2) + (2*i*h*g)*diff(Y,theta) == g^2;
cond = Y(0) == cos(theta);
Y(theta) = dsolve(eqn)
This solver works, but it is completely indifferent to whatever I write in the cond line. Is that some form of mis-writing here I have done?
Thanks
Why wasn't the documentation helpful? https://www.mathworks.com/help/symbolic/solve.html
Karan (Symbolic doc)
See conversation with Birdman, MATLAB beta online and MATLAB alpha on the local machine treat the conditions differently.
What's your MATLAB version on the computer?
Hi Karan, it's
MATLAB Version 9.2 (R2017a)

Sign in to comment.

 Accepted Answer

Hi Sergio,
syms y(t) z(t)
h=4.5;
g=4/pi;
eqns=h^2*[diff(y,t)+2*i*g*y+g^2==0,diff(z,t)==y];
sol=dsolve(eqns);
y=vpa(sol.y,4)
z=vpa(sol.z,4)
I assume that the numeric constants are the same with previous question, the struct sol actually holds the solution of these diff equation set wrt y and z respectively. Actually it has solution. Why don't you check it once more?

5 Comments

Hi Birdman, thanks for checking this further, I am actually looking at MuPAD options now, because I solved this system 3 months ago with MATLAB; but I lost my command file. Now, when I redo it, I get a completely different solution, and the old solution which is rather "elegant":
y = C - e^(-2ig x/h)* [C-Bcos(x) + gx/2ih],
As you can see, Bcos(x) is in the picture, and I used it as initial condition for the ODE:
h^2Y'' + 2ighY' = g^2
What you wrote does not have that initial condition. I check Wolfram ALpha, which was, surprisingly, able to solve it with initial condition y(0)= Bcos(x) and y'(0)= Dsin(x) - a moment, then retrying it there as well, all disappeared. It is really concerning that, one cannot reproduce a calculation with such programs. Of course, its my fault who did not save the original command (which is lost in the online MATLAB account) and the local drives, but such a simple system with two conditions?
Sergio Manzetti
Sergio Manzetti on 8 Dec 2017
Edited: Sergio Manzetti on 8 Dec 2017
Because I have only x, in 1 D. PDE would be a completely different system with a y coordinate too. I am puzzled by the fact one can use an initial condition as a function in Wolfram Alpha for a regular ODE, and possible in MATLAB too (as I did before), but now one has to use values in initial conditions.
I have no further idea about it Sergio, so that's it from me :)
Birdman, now suddenly MATLAB online manages to reproduce the solution. I give the entire code here:
if true
% code
end
syms a h Y(theta) g x B
eqn = h^2*diff(Y,theta, 2) + (2*i*h*g)*diff(Y,theta) == g^2;
cond = Y(0) == cos(x);
Y(theta) = dsolve(eqn, cond)
and the solution is indeed:
C16 - exp(-(g*theta*2i)/h)*(C16 - cos(x)) - (g*theta*1i)/(2*h)
however, cos(x) is a constant as the variable is theta, so how do I solve this? Really not sure.

Sign in to comment.

More Answers (1)

Birdman, have a look at this
if true
% code
end
syms a h Y(theta) g x
eqn = h^2*diff(Y,theta, 2) + (2*i*h*g)*diff(Y,theta) == g^2;
cond = Y(0) == cos(x);
Y(theta) = dsolve(eqn)
This one did not complain about the condition, in fact, it even ignored it.

3 Comments

Sergio Manzetti
Sergio Manzetti on 8 Dec 2017
Edited: Sergio Manzetti on 8 Dec 2017
I think there is a differece here between Matlab Online (beta) and Matlab on the computer (alpha).
Beta yields as answer to the code above:
C6 + C7*exp(-(g*theta*2i)/h) - (g*theta*1i)/(2*h)
which is close to my original answer with initial conditions (still not reproduced entirely though cos(x) missing). MATLAB alpha however gives:
Error using mupadengine/feval (line 166) No differential equations found. Specify differential equations by using symbolic functions.
Error in dsolve>mupadDsolve (line 336) T = feval(symengine,'symobj::dsolve',sys,x,options);
Error in dsolve (line 194) sol = mupadDsolve(args, options);
Error in PDE_sol (line 9) Y(theta) = dsolve(eqn)
Do you mind if I look at this at weekend?
Sergio Manzetti
Sergio Manzetti on 8 Dec 2017
Edited: Sergio Manzetti on 8 Dec 2017
That is fine, I have found out that cos(x) which is invalid as an initial condition - as you correctly said, was treated as a constant by MATLAB online using that command, while MATLAB alpha on the computer did not let that be solved. This means remaking the current system to a 2D PDE problem (like you also suggested with the pdpe link) is one option, or simplify the initial conditions of the 1D problem. It appears that the latter is is sound. We'll see. Thanks, have a good weekend

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!