matlab secant method

% Matlab script to illustrate the secant method

% to solve a nonlinear equation

% this particular script finds the square root of a number M

% (input by the user)

% note that the function we are trying to zero is f(x) = x^2 - M.

% this function is hard-coded in the script.

g=9.8065;

k=0.00341;

% f(x)=log(cosh(t*srt(g*k)))/k;

format long

% get user input

M = input(‘Please enter the number whose square root you want: ‘)

t0 = input(‘Please enter the first  of two starting guesses: ‘)

t1 = input(‘Please enter the second of two starting guesses: ‘)

% iteration counter

k = 1

% compute first secant iterate to enter loop

s = (((log(cosh(t1*sqrt(g*k)))/k)-M)-((log(cosh(t0*sqrt(g*k)))/k)-M) )/(t1-t0);

% s = ( (x1^2-M) - (x0^2-M) ) / (x1 - x0);

t = t1 - (((log(cosh(t1*sqrt(g*k)))/k)-M))/s

% x = x1 - (x1^2-M)/s

disp(‘Hit return to continue‘)

pause

while abs(t-t1) > eps*abs(t),

% reset guesses

t0 = t1;

t1 = t;

% increment iteration counter

k = k + 1

% compute and display secant iterate

s = (((log(cosh(t1*sqrt(g*k)))/k)-M)-((log(cosh(t0*sqrt(g*k)))/k)-M) )/(t1-t0);

%     s = ( (x1^2-M) - (x0^2-M) ) / (x1 - x0);

%     x = x1 - (x1^2-M)/s

t = t1 - (((log(cosh(t1*sqrt(g*k)))/k)-M))/s

disp(‘Hit return to continue‘)

pause

end

时间: 2024-10-16 00:33:55

matlab secant method的相关文章

matlab Newton method

% Matlab script to illustrate Newton's method % to solve a nonlinear equation % this particular script finds the square root of a number M % (input by the user) % note that the function we are trying to zero is f(x) = x^2 - M. % its derivative is f'(

非线性方程(组):一维非线性方程(二)插值迭代方法 [MATLAB]

一般而言,方程没有能够普遍求解的silver bullet,但是有几类方程的求解方法已经非常清晰确凿了,比如线性方程.二次方程或一次分式.一次方程可以直接通过四则运算反解出答案,二次方程的求根公式也给出了只需要四则运算和开根号的符号表达式.而一次分式的分子即为一次函数.更多的方程并没有普适的符号表达式,但通过用便于求零点的函数模仿.代替之也可以估计零点的位置.插值方法可以实现这一思路. 插值迭代方法包括割线法.二次插值法等多项式插值方法,反插法以及线性分式插值法等等,其核心是用几个点及其函数值信

<Numerical Analysis>笔记

2ed, by Timothy Sauer DEFINITION 1.3A solution is correct within p decimal places if the error is less than 0.5 × 10$^{−p}$ .-P29Bisection Method的优点是计算次数(step)是确定的(interval<精度).后面介绍的算法的interval是不确定的, 所以什么时候结束计算呢?不知道.所以定义“stopping criteria’’来决定什么时候结束计

Stochastic Optimization Techniques

Stochastic Optimization Techniques Neural networks are often trained stochastically, i.e. using a method where the objective function changes at each iteration. This stochastic variation is due to the model being trained on different data during each

弦截法求方程根

THE SECANT METHOD In numerical analysis, the secant method is a root-finding algorithm that uses a succession of roots of secant lines to better approximate a root of a function f. The secant method can be thought of as a finite difference approximat

C200 Programming Assignment

C200 Programming Assignment № 8Computer ScienceSchool of Informatics, Computing, and EngineeringMarch 30, 2019ContentsIntroduction 2Problem 1: Newton Raphson Root Finding Algorithm 4Root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Least square method using matlab

download linux-matlab: after the installing step: 1), change the current folder for working folder: add the content to ***/installed folder/toolbox/local/matlabrc.m cd 'cd '/home/groot/Music/java_2017/hadoop_r-base/matlab_plot' 2), deal with error af

Matlab Newton‘s method

定义函数 function y=f(x) y=f(x).%函数f(x)的表达式 end function z=h(x) z=h(x).%函数h(x)的表达式 end 主程序 x=X;%迭代初值 i=0;%迭代次数计算 while i<= 100%迭代次数 x0=X-f(X)/h(X);%牛顿迭代格式 if abs(x0-X)>0.01:%收敛推断 X=x0; else break end i=i+1; end fprintf('\n%s%.4f\t%s%d','X='.X.'i='.i) %产

Matlab中所有自定义的函数

Functions By Category | Alphabetical List Language Fundamentals Entering Commands ans Most recent answer clc Clear Command Window diary Save Command Window text to file format Set display format for output home Send cursor home iskeyword Determine wh