How to solve and plot a differential equation

์กฐํšŒ ์ˆ˜: 31 (์ตœ๊ทผ 30์ผ)
AUSTIN WHITELEY
AUSTIN WHITELEY 2022๋…„ 1์›” 18์ผ
๋‹ต๋ณ€: Vandit 2023๋…„ 6์›” 28์ผ
Use Matlab to solve for the matrix ๐‘ด and the vector ๐นโƒ— . Plot the concentration in each compartment vs. time. dC/dt + ๐‘€๐ถโƒ— = ๐นโƒ—
C= [c1; c2]
when dC/dt=0, c1=.8333 c2=2.08333.
Here's what I have in terms of code
C=[c1; c2];
M= [1.5 -.12; -1 .4];
F=[1; 0];
syms c(t)
ode= diff (c,t) + M*C == F
sol=dsolve(ode)
fplot(sol,[0,5]);
It is having trouble with the fact that C is a vector with two other variables.
  ๋Œ“๊ธ€ ์ˆ˜: 2
James Tursa
James Tursa 2022๋…„ 1์›” 18์ผ
You have numeric values for M and F?
AUSTIN WHITELEY
AUSTIN WHITELEY 2022๋…„ 1์›” 18์ผ
yes.
M= [1.5 -.12; -1 .4];
F=[1; 0];

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

๋‹ต๋ณ€ (1๊ฐœ)

Vandit
Vandit 2023๋…„ 6์›” 28์ผ
Hi,
Below is the updated MATLAB code that solves the given differential equation and plot the concentration in each compartment over time :
M = [1.5 -0.12; -1 0.4];
F = [1; 0];
c1=.8333
c2=2.08333;
C0 = [c1; c2];
tspan = [0 10]; % Adjust the time span as needed
% Solve the differential equation
[t, C] = ode45(@(t, C) M*C + F, tspan, C0);
% Plot the concentration in each compartment vs. time
figure;
plot(t, C(:, 1), 'b', 'LineWidth', 2); % Compartment 1
hold on;
plot(t, C(:, 2), 'r', 'LineWidth', 2); % Compartment 2
xlabel('Time');
ylabel('Concentration');
legend('Compartment 1', 'Compartment 2');
title('Concentration vs. Time');
grid on;
I have also attached the output plot which should be obtained after running the above code in MATLAB.
To know more about the Ordinary Differential Equations refer to the link below:
Hope this helps.
Thankyou

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Programming์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

์ œํ’ˆ


๋ฆด๋ฆฌ์Šค

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by