Homework 3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

3/3/24 12:08 AM C:\Users\Admin\bai24.

m 1 of 1

%Bai24
function[chenhlech1,chenhlech2] = bai24()
h = 0.25;
t = [0:h:2];
z = [1 2]; % hai gia tri xet do lech theo de bai
w = (-1./exp(z) + 1); %ket qua tinh bang giai tich cua phuong trinh vi phan
y = zeros(1,length(t));
y(1) = 0;
for k = 2:length(t)
y(k) = y(k-1) + h*(1-y(k-1));
end
chenhlech1 = (abs(w(1) - y(1/h+1))/w(1)) *100; %do chenh lech tinh theo '%'
chenhlech2 = (abs(w(2) - y(2/h+1))/w(2)) * 100;%do chenh lech tinh theo '%'
end
%Bai25
function[chenhlech1,chenhlech2] = bai25()
h = 0.25;
t = [0:h:2];
z = [1 2]; % hai gia tri xet do lech theo de bai
w = (-1./exp(z) + 1); %ket qua tinh bang giai tich cua phuong trinh vi phan
y = zeros(1,length(t));
y(1) = 0;
for k = 2:length(t)
y(k) = y(k-1) + h*(1-y(k-1));
end
chenhlech1 = (abs(w(1) - y(1/h+1))/w(1)) *100; %do chenh lech tinh theo '%'
chenhlech2 = (abs(w(2) - y(2/h+1))/w(2)) * 100;%do chenh lech tinh theo '%'
end
%Bai26
function[chenhlech1,chenhlech2] = bai26()
h = 0.25;
t = [0:h:2];
z = [1 2]; % hai gia tri xet do lech theo de bai
w = (-1./exp(z) + 1); %ket qua tinh bang giai tich cua phuong trinh vi phan
y = zeros(1,length(t));
y(1) = 0;
for k = 2:length(t)
y(k) = y(k-1) + h*(1-y(k-1));
end
chenhlech1 = (abs(w(1) - y(1/h+1))/w(1)) *100; %do chenh lech tinh theo '%'
chenhlech2 = (abs(w(2) - y(2/h+1))/w(2)) * 100;%do chenh lech tinh theo '%'
end
%Bai27
function[t,y] = bai27()
h = 0.01;
t = 0:h:3;
y = zeros(1,length(t));
y(1) = 1;
for k = 2:length(t)
y(k) = y(k-1) + h*(-1/(10*10^3*4.7*10^-6))*(y(k-1)-1);
end
end

You might also like