Euler Method Tank + Salt
4 views (last 30 days)
Show older comments
Hello!
clear; close all; clc
%% Parameters
tank1 = 100; % gallons
tank2 = 100; % gallons
tank1salt = 1000; % grams of salt
tank2salt = 100; % grams of salt
h = 0.01; % step size
f1 = @(x,y) (5/100)*y - (15/100)*x
f2 = @(x,y) (15/100)*x - (15/100)*y
f = [f1, f2];
function [t,y] = ode_eulerfinal(f, tspan, y0, h)
f =
t = tspan(1):h:tspan(2);
y = nan(size(t));
y(1) = y0;
for i = 1:length(t)-1
y(i+1) = y(i) + h * f(t(i), y(i));
end
end
0 Comments
Answers (0)
See Also
Categories
Find more on Assembly in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!