Why is it the answer from MATLAB is different from the other solving software? Where did I go wrong?

2 visualizaciones (últimos 30 días)
>> syms y(T)
eqn = diff(y(T),T)==(k*(y-80));
cond1 = y(0)==20;
cond2 = y(1)==35;
y=dsolve(eqn,cond)
y =
80 - 75*exp(T*k)
Hello!
The code above says that the answer is 80 - 75*exp(T*k)
But when I checked it on another software it is
80 - 60*exp(T*k)
May I know where did I go wrong? Thank you and God bless!

Respuesta aceptada

John D'Errico
John D'Errico el 27 de Jul. de 2020
Editada: John D'Errico el 27 de Jul. de 2020
Usually when I see a confused question, where someone says "help, i got a strange answer", the reason is because they were not careful in what they wrote. Here, for example, the code you claim to have used in MATLAB would not actually run. It would produce an error message, because while you have defined cond1 and cond2, then you call dsolve with the variable cond. As well, you never even defined k. What is k? How should MATLAB respond when you don't define variables? So if you did get an answer, then the answer you did get was based on some things we do not see at all.
When you see a problem, start from the beginning. Verify that when you think is in the variables you used, is what you actually have in those variables.
Next, what you seem to be wanting to claim, is that the problem with TWO boundary values, that at T ==0, AND at T == 1, will yield the solution you have. And that claim is incorrect.
syms y(T)
syms k real
eqn = diff(y(T),T)==(k*(y-80));
ysol=dsolve(eqn,y(0) == 20)
ysol =
80 - 60*exp(T*k)
As you should see, With only ONE condition, at T == 0, we get the same solution that you claim the other code provides.
However, with a second boundary value at T == 1, the problem would be unsolvable, unless the second condition happens to be consistent with the first.
subs(ysol,T,0)
ans =
20
subs(ysol,T,1)
ans =
80 - 60*exp(k)
Now, we could solve for the value of k, such that this second equation happens to result in y(1)==35.
ksol = solve(subs(ysol,T,1) == 35)
ksol =
log(3/4)
We would then need to substiture that BACK into the equation, eliminating k.
yfinalsol = subs(ysol,k,ksol)
yfinalsol =
80 - 60*exp(T*log(3/4))
subs(yfinalsol,T,0)
ans =
20
subs(yfinalsol,T,1)
ans =
35
But as you see, IF your goal is to satisfy BOTH conditions, at T==0, AND at T == 1, then you will no longer have the solution you think you got from the other software.
Finally, the solution you claim to have gotten, happens to be the solution of a related problem:
dsolve(eqn,y(0) == 5)
ysol =
80 - 75*exp(T*k)
It was simple enough to recover what the initial condition needed to be, to have gotten the solution you claim to have gotten, since if you got that solution, then at T == 0, y would need to be 5.
subs(80 - 75*exp(T*k),T,0)
ans =
5
But in no respect is it the problem you have posed.
Mathematics is both simple as well as unforgiving.
  1 comentario
Yvonne Carol Baruc
Yvonne Carol Baruc el 27 de Jul. de 2020
Hello Sir!
There is so much enlightenment happened to me when I read your answer and I also realized where I go wrong.
Thank you so much for your response and I appreciate it a lot. I just downloaded the MATLAB an hour before I posted the question and I really admit that I know nothing at all. Thank you for the guidance! I hope I can learn more in this community. God bless.

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord
Steven Lord el 27 de Jul. de 2020
Don't name your variable cond. That already has a meaning in MATLAB.
When I used cond1 in the dsolve call rather than cond I received the expected answer.
>> syms y(T) T k
>> eqn = diff(y(T),T)==(k*(y-80));
>> cond1 = y(0)==20;
>> ysol = dsolve(eqn, cond1)
ysol =
80 - 60*exp(T*k)
  1 comentario
Yvonne Carol Baruc
Yvonne Carol Baruc el 27 de Jul. de 2020
Hello Sir!
I got the same result when I only used cond1. Just like Sir John said in his answer, I am trying to satisfy both y(0)=20 and y(1)=35. But it is all now solved, thanks to both of you!
Thank you so much for your response, I appreciate it a lot. I just downloaded the MATLAB an hour before I posted the question and I really admit that I know nothing at all,just following the guides here in MATLAB. Thank you for guidance! I hope I can learn more in this community. God bless.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by