How can I define this differential equation in matlab syntax to solve it using ode45 ?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Namit Dayal
le 5 Déc 2023
Réponse apportée : Sam Chak
le 6 Déc 2023
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1560764/image.png)
I want to solve this equation for tau,
gammadot is not a differential term
the values for lamda1, lambda2, eta0, gamma are known
edit: I just want to know how to write this equation in a way that matlab understands
2 commentaires
Torsten
le 5 Déc 2023
Was there something unclear about the responses you already received for this question ?
Réponse acceptée
Sam Chak
le 6 Déc 2023
Hi @Namit Dayal
Depending on the values of
, this is one way to solve the differential equations using the 'ode45()' solver. Here, I assume that
grows linearly with time, as illustrated in the third subplot.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1561589/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1561594/image.png)
tspan = [0 1000];
y0 = [1 0 0];
[t, y] = ode45(@odefcn, tspan, y0);
subplot(311)
plot(t, y(:,1)), grid on, ylabel \tau
subplot(312)
plot(t, y(:,2)), grid on, ylabel \gamma
subplot(313)
plot(t, y(:,3)), grid on, ylabel \gamma\prime, xlabel t
%% Differential equations
function dydt = odefcn(t, y)
dydt = zeros(3, 1);
eta0 = 8080;
lambda1 = 1.109;
lambda2 = lambda1;
dydt(1) = - (y(1) + eta0*y(3) + eta0*lambda2*1)/lambda1;
dydt(2) = t; % gammadot = t (grows linearly from 0 to 1000 in 1000 s)
dydt(3) = 1; % d gammadot/dt = 1 (differentiate t with respect to t)
end
0 commentaires
Plus de réponses (1)
Sam Chak
le 5 Déc 2023
Hmm... @Namit Dayal, but you declared that "gammadot is not a differential term". Thus, only
is regarded as the differential term. Also, the values for the rest of the parameters
,
,
, and
are known. If these values are constants such that
, then
, and the differential equation can be reduced to
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1560989/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1560994/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1560999/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1561004/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1561009/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1561014/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1561019/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1561024/image.png)
The analytical solution for this first-order ODE is given by
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1561029/image.png)
where
is the initial value.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1561034/image.png)
I hope you have disclosed all information regarding this math problem. If my assumption about
is incorrect, then the solution becomes illegitimate.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1561039/image.png)
4 commentaires
Torsten
le 5 Déc 2023
I have a doubt, suppose gamma is a set of values from 0.001 to 1000, then will d(gamma)/dt be equal to zero as well ?
In your preceding question that can be found here
I asked
Do you want to compute one function for tau and treat gamma(dot) is a function of t
or
do you want to compute as many functions tau as there are parameters for gamma(dot) and treat gamma(dot) as constant for each of these computations ?
and you answered
I want to treat gamma(dot) as a vector of constants and solve for tau for all values of gamma(dot) separately
Assuming the same is true here, @Sam Chak gave you the solution of the differential equation with gammadot = constant and thus d(gammadot)/dt = 0 (although I doubt this is meant in the differential equation).
Sam Chak
le 6 Déc 2023
Modifié(e) : Sam Chak
le 6 Déc 2023
Perhaps the OP didn't know how to express the problem to us. 'gammadot' (
) is indeed a differential term, but it appears as a time-dependent term in data form. If that's the case, then the interpolation method using interp1() can be applied.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1561384/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1561394/image.png)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!