ODE45, differential equation
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Takey Asaad
am 14 Sep. 2018
Bearbeitet: Stephan
am 17 Sep. 2018
my function is
dy/dt=k*y*exp(450/y)
k is constant and y(0)=40 and y(15)=95 solve this equation by using ode45 can someone pleaseeeeeeeeeee check the code and make it work .
tspan = [0 300];
y0 = 40;y15=95
[t,y] = ode45(@(t,y) 'k'*y*exp(450/y), tspan, y0,y15);
plot(t,y,'-o')
0 Kommentare
Akzeptierte Antwort
Stephan
am 16 Sep. 2018
Bearbeitet: Stephan
am 17 Sep. 2018
Hi,
if you search a value for k that complies with the boundary conditions, you could use fzero to solve the problem numerically:
k = fzero(@calculate_k, 0.001);
disp(['k = ', num2str(k)])
[t,y] = ode45(@(t,y) k*y*exp(450/y), [0 300], 40);
plot(t,y,'r')
hold on
scatter(15,95,'ob')
text(23,96,'y(t=15) = 95','Color','b')
hold off
function k_value = calculate_k(x)
tspan = [0 15];
y0 = 40;
[~,y] = ode45(@(t,y) x*y*exp(450/y), tspan, y0);
k_value = y(end) - 95;
end
This will give you as result:
k = 0.00010435
or if you need it more accurate:
k =
1.043495007807761e-04
and the plot which belongs to this result looks like the boundary conditions are met (To be precise, it keeps the boundary conditions. This is because fzero is a powerful tool and also because you can think of a very good initial value for x0 with just a few estimates...):
.
Best regards
Stephan
2 Kommentare
Stephan
am 17 Sep. 2018
Bearbeitet: Stephan
am 17 Sep. 2018
No problem - please be patient with your questions. Dont ask the same question a second time, if it needs more time than you expected to get an answer.
Better try to give as much as and as good as possible informations that are needed to let the contributers give you a useful answer.
Weitere Antworten (3)
James Tursa
am 15 Sep. 2018
Remove the quotes from 'k', and be sure to define k before you call ode45. Also, ode45 is an initial value problem solver, so the y15 variable is not applicable (remove it from the call).
9 Kommentare
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!