روشهای عددی برای حل معادلات غیر خطی(اسکالر)
روش تنصیف
====================================================
در این روش با تقسیم های متوالی بازه ای که شامل ریشه است به مقدار دقیق ریشه نزدیک می شویم:
الگوریتم:
1) مقادیر a و b را چنان بیابید که f(a)f(b)<0
2) قرار دهید c=(a+b)/2
3) اگر f(a)f(c)<0 قرار دهید b=c در غیر اینصورت قرار دهید a=c
4) اگر f(c)|<tol| خاتمه دهید. در غیر اینصورت برو به 2.
که در آن tol دقت مطلوب می باشد.
کد Matlab برای روش تنصیف(دو بخشی):
% Bisection Method
% Written by Dr. Javad Farzi 2-17-2015
% Sahand University of Technology
% farzi@sut.ac.ir
% http://comput-sut.persianblog.ir/
% This is a simple matlab code for implementation of bisection method.
% You can modify this code to solve a general scalar nonlinear equation.
% It is recommended to modify this code and write it as a Matlab function.
clc
% define the function and the interval [a,b] that contains the root of
% f(x)=0.
f=@(x)(3*x.*exp(x)-1); a = 0; b = 1;
% f = @(x)(x.^3+4*x.^2-10); a = 1; b = 2;
% Plot the given function
x = linspace(a,b,100);
plot(x,f(x)), grid, hold on
disp('i a b c f(c)')
disp('------------------------------------------------------')
% The main loop for bisection method:
for i=1:13
c = (a+b)/2;
% print the data:
fprintf('%2g %f %f %f %10.2e \n',i,a,b,c,f(c))
% if you want to run the all steps altogether set comment
% symbol % for the following line or remove it:
pause(0.6)
% plot the approximate values evaluated with bisection method:
plot(c,f(c),'ro'), hold on
if f(c)*f(a)<0
b = c;
else
a = c;
end
end
disp('------------------------------------------------------')
____________________________________________________________________
____________________________________________________________________
دستورات Maple برای روش تنصیف:
with(Student[NumericalAnalysis]);
f := x^3-7*x^2+14*x-6;
Bisection(f, x = [2.7, 3.2], tolerance = 10^(-2));
3 2
x - 7 x + 14 x - 6
2.996875000
Bisection(f, x = [2.7, 3.2], tolerance = 10^(-2), output = sequence);
[2.7, 3.2], [2.950000000, 3.2], [2.950000000, 3.075000000],
[2.950000000, 3.012500000], [2.981250000, 3.012500000],
2.996875000
Bisection(f, x = [2.7, 3.2], tolerance = 10^(-2), stoppingcriterion = absolute);
3.004687500
Bisection(f, x = [3.2, 4.0], output = animation, tolerance = 10^(-3), stoppingcriterion = function_value);
____________________________________________________________________
روش نیوتن
====================================================
روش نیوتن برای حل معادلات غیر خطی به صورت
استفاده می شود. یعنی برای حل یا پیدا کردن ریشه ها(صفرهای) معادلات از این روش استفاده می شود.
عملکرد روش نیوتن در شکل زیر مشخص است
رابطه بازگشتی این روش هم عبارتست از:
بنابراین، مثلا برای محاسبه ریشه ششم عدد 2 باید تابعی در نظر بگیرید که این عدد ریشه آن تابع باشد. یعنی
جواب این معادله همان است که می خواهیم آن را محاسبه کنیم. بنابراین داریم
و روش نیوتن برای این تابع عبارتست از
با شروع از مقدار اولیه نتایج زیر بدست می آید: