Having problem to change the value of extra parameters at each time step passed in ODE45 Solver
Show older comments
Hello, I have a set of two diffrential equations having some constants i.e. A, B, C and D and i have passed these extra parametres successfully in ODE45 solver too. I'm getting my results as well.
As i'm solving these equations for specific time i.e. at t= 0, 1, 2,.......10.
Now what I want to do is that I want to change the values of A, B, C and D at each time i.e at t=0 I have some values of A,B,C and D and then at t=1 I need to use different values of these constants and so on.
Here's code and a picture of my two differential equations.
clc
clear all
close all
A=1;
B=-4;
C=-2;
D=3;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% d1 w1 d2 w2
[t,y] = ode45(@(t,y) aa(t,y,A,B,C,D),[0:1:10], [5 -3]);
plot(t,y(:,1),t,y(:,2))
xlabel('Time t');
ylabel('Solution y');
legend('y_1','y_2')
function dydt1 = aa(t,y,A,B,C,D)
dydt1 = zeros(2,1);
dydt1(1) = A.*y(1)+B.*y(2).*(2.*y(1));
dydt1(2) = C.*y(1)+D.*(2.*y(1));
end
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!