ode with varying constant
Mostra commenti meno recenti
i have one differntial eqation and in that i have two constants one is scalar and one is vector i have to solve diffential equation for each value of vector means i got no of diff equation= no of elements in vector now i have to plot each solution of each de with time
function [dydt] = diffvar(t,y)
dydt=-k*y+a;
end
3 Commenti
Ameer Hamza
il 21 Ott 2020
Modificato: Ameer Hamza
il 21 Ott 2020
What about my answer to your other question: https://www.mathworks.com/matlabcentral/answers/621608-how-to-solve-ode-if-value-of-constant-is-vector
prajyot gajbhiye
il 21 Ott 2020
Ameer Hamza
il 21 Ott 2020
That code will work even if you put one of the variable as scalar.
Risposte (1)
Star Strider
il 21 Ott 2020
Interpolating a time-domain vector in a differential equation is essentially described in the ode45 (and other solvers) documentation. This simply re-states it in the context of the current problem.
Try this
ic = 0;
tspan = [0 10];
k = 42;
av = rand(1,10); % Vector Defining ‘a’
a = @(t) interp1(linspace(min(tspan),max(tspan),numel(av)), av, t); % Function Interpolating ‘a’
[T,Y] = ode45(@(t,y)diffvar(t,y,k), tspan, ic);
figure
plot(T, Y)
grid
function [dydt] = diffvar(t,y,k)
dydt=-k*y+a(t); % Call ‘a’ As A Function
end
Use your own vector for ‘av’ and your own constant for ‘k’.
Categorie
Scopri di più su Ordinary Differential Equations in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!