I have a homework assignment that I'm not sure how to do, the professor did not teach us anything about the matlab ode45 function. I have the line of code that I have so far but I'm not sure whats wrong.

1 view (last 30 days)
function HW1Q3
clear;
clc;
t0 = 0;
tf = 30;
C0= [0 50];
soln = ode45(@f, [t0 tf], C0);
t=linspace(0,tf,100);
C1=deval(soln,t,1);
C2=deval(soln,t,2);
plot(t,C1,'-k',t,C2,'-r','LineWidth',2);
xlabel('t');
ylabel('C');
grid on;
title('HW1, Q3')
end
function dCdt = f(t,C)
V = 2;
q = 0.4;
Ci= 50;
dCdt(1) = -(q/V)*C(1);
dCdt(2) = (q/V)*(Ci-C(2));
dCdt = dCdt';
end

Accepted Answer

Torsten
Torsten on 5 Feb 2018
function HW1Q3
clear;
clc;
t0 = 0;
tf = 30;
C0 = 0;
soln = ode45(@f, [t0 tf], C0);
t=linspace(0,tf,100);
C1=deval(soln,t,1);
plot(t,C1,'-k','LineWidth',2);
xlabel('t');
ylabel('C');
grid on;
title('HW1, Q3')
end
function dCdt = f(t,C)
V = 2;
q = 0.4;
Ci = 50;
dCdt(1) = (q/V)*(Ci-C(1));
end

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!