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 commentaires

John D'Errico
John D'Errico le 8 Déc 2017
Modifié(e) : John D'Errico le 8 Déc 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?
Sergio Manzetti
Sergio Manzetti le 8 Déc 2017
I am trying to know what the output means John, it has no solution as it stands.
John D'Errico
John D'Errico le 8 Déc 2017
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?
Sergio Manzetti
Sergio Manzetti le 8 Déc 2017
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
Sergio Manzetti
Sergio Manzetti le 8 Déc 2017
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
Karan Gill
Karan Gill le 8 Déc 2017
Why wasn't the documentation helpful? https://www.mathworks.com/help/symbolic/solve.html
Karan (Symbolic doc)
Sergio Manzetti
Sergio Manzetti le 8 Déc 2017
See conversation with Birdman, MATLAB beta online and MATLAB alpha on the local machine treat the conditions differently.
Karan Gill
Karan Gill le 11 Déc 2017
What's your MATLAB version on the computer?
Sergio Manzetti
Sergio Manzetti le 12 Déc 2017
Hi Karan, it's
MATLAB Version 9.2 (R2017a)

Connectez-vous pour commenter.

 Réponse acceptée

Birdman
Birdman le 8 Déc 2017

1 vote

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 commentaires

Sergio Manzetti
Sergio Manzetti le 8 Déc 2017
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?
Birdman
Birdman le 8 Déc 2017
Sergio Manzetti
Sergio Manzetti le 8 Déc 2017
Modifié(e) : Sergio Manzetti le 8 Déc 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.
Birdman
Birdman le 8 Déc 2017
I have no further idea about it Sergio, so that's it from me :)
Sergio Manzetti
Sergio Manzetti le 8 Déc 2017
Modifié(e) : Sergio Manzetti le 8 Déc 2017
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.

Connectez-vous pour commenter.

Plus de réponses (1)

Sergio Manzetti
Sergio Manzetti le 8 Déc 2017

0 votes

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 commentaires

Sergio Manzetti
Sergio Manzetti le 8 Déc 2017
Modifié(e) : Sergio Manzetti le 8 Déc 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)
Birdman
Birdman le 8 Déc 2017
Do you mind if I look at this at weekend?
Sergio Manzetti
Sergio Manzetti le 8 Déc 2017
Modifié(e) : Sergio Manzetti le 8 Déc 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

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by