Last active
April 23, 2021 19:40
-
-
Save lecuseasar/e776024611712b34aa5d1a0905d85a57 to your computer and use it in GitHub Desktop.
my matlab homework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Aşağıdaki lineer olmayan bir denklem verilmektedir. | |
% f(x)=e^(-x)-x | |
% Denkleminin köklerini hem grafik yöntemi hem de Fixed Point yöntemi ile çözen programı yazınız. x1 =0, tol=0.01 bitirme koşulu olarak abs(x2-x1) <tol ifadesini kullanınız. | |
clc; clear; close all; | |
fprintf('Fixed Point yontemi kullanarak f(x)=e^(-x)-x denkleminin koklerini bulmak\n'); | |
%Bilir kişinin verdiği değerler verdiğiniz değerler | |
x1 = 0; | |
tol = .01; | |
for x1 = 0:.01:2 | |
y = x1; | |
fx = exp(1)^((-x1) - x1); | |
plot(x1, y, 'r.', x1, fx, 'b.'); | |
hold on; | |
grid on; | |
xlabel('x'); | |
ylabel('y'); | |
text(.4, .9, 'red y=x') | |
text(.4, .8, 'blue y=e^(-x)-x'); | |
end | |
x1 = 0; | |
%fprintf('Iter. | x1 | x2 | absolute_error | relative_error |\n'); | |
for i = 1:50 | |
x2 = exp(1)^((-x1) - x1); | |
absolute_error = abs(x2 - x1); | |
relative_error = absolute_error / abs(x2); | |
fprintf('iter: %4.0f |x1: %7.4f |x2: %7.4f |absolute_error: %7.4f |relative_error: %7.4f |\n\n', i, x1, x2, absolute_error, relative_error); | |
if abs(x2 - x1) < tol | |
break; | |
else | |
x1 = x2; | |
end | |
end | |
disp('Denklemin Koku'); | |
disp(x2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment