% 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

matlab secant method的更多相关文章

  1. Secant Method (Website)

    Secant Method:  https://www.youtube.com/watch?v=qC9xnsfOd30 Secant Method : http://mathworld.wolfram ...

  2. matlab Newton method

    % Matlab script to illustrate Newton's method % to solve a nonlinear equation % this particular scri ...

  3. The Secant Method(正割法、弦截法) 附C语言代码

    弦截法是一种求方程根的基该方法,在计算机编程中经常使用. 他的思路是这种:任取两个数x1.x2,求得相应的函数值f(x1).f(x2).假设两函数值同号,则又一次取数.直到这两个函数值异号为止. 连接 ...

  4. Todd's Matlab讲义第6讲:割线法

    割线法 割线法求解方程\(f(x)=0\)的根需要两个接近真实根\(x^\*\)的初值\(x_0\)和\(x_1\),于是得到函数\(f(x)\)上两个点\((x_0,y_0=f(x_0))\)和\( ...

  5. 牛顿方法(Newton-Raphson Method)

    本博客已经迁往http://www.kemaswill.com/, 博客园这边也会继续更新, 欢迎关注~ 牛顿方法是一种求解等式的非常有效的数值分析方法. 1.  牛顿方法 假设\(x_0\)是等式的 ...

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

    一般而言,方程没有能够普遍求解的silver bullet,但是有几类方程的求解方法已经非常清晰确凿了,比如线性方程.二次方程或一次分式.一次方程可以直接通过四则运算反解出答案,二次方程的求根公式也给 ...

  7. Secant 方法求方程多个根

    Secant 方法介绍 Secant Method 函数 Secant_Methods 简介 1.函数定义 [c, errColumn] = Secant_Method(f, a, b, N, con ...

  8. <<Numerical Analysis>>笔记

    2ed,  by Timothy Sauer DEFINITION 1.3A solution is correct within p decimal places if the error is l ...

  9. <Numerical Analysis>(by Timothy Sauer) Notes

    2ed,  by Timothy Sauer DEFINITION 1.3A solution is correct within p decimal places if the error is l ...

随机推荐

  1. LaTeX新人教程,30分钟从全然陌生到基本入门

    1.LaTeX软件的安装和使用  方法A(自助):在MikTeX的官网下载免费的MikTeX编译包并安装.下载WinEdt(收费)或TexMaker(免费)等编辑界面软件并安装.  方法B(打包):在 ...

  2. Swift - 点击输入框外部屏幕关闭虚拟键盘

    我们如果把文本框的Return Key设置成Done,然后在storyboard中将文本框的Did End On Exit事件在代码里进行关联.同时关联代码里调用文本框的resignFirstResp ...

  3. 熬之滴水穿石:JSP--HTML中的JAVA代码(6)

                                                                       39--JSTL 在JSP编码中需考虑的一种方法,因为这种方法可以 ...

  4. 【Visual C++】Windows GDI贴图闪烁解决方法

    一般的windows 复杂的界面需要使用多层窗口而且要用贴图来美化,所以不可避免在窗口移动或者改变大小的时候出现闪烁. 先来谈谈闪烁产生的原因 原因一:如果熟悉显卡原理的话,调用GDI函数向屏幕输出的 ...

  5. leetcode第一刷_Sqrt(x)

    这道题乍看下来很easy,实际上要注意的问题许多. 注意看给出来的函数的接口,返回的是int值,也就是计算结果是个近似值.如何求呢?难道是从2開始往上算?直到某个值正好接近x?当然不行,肯定超时了.再 ...

  6. C#日期函数使用大全

    1 DateTime dt = DateTime.Now; 2 3 dt.ToString();//2005-11-5 13:21:25 4 5 dt.ToFileTime().ToString(); ...

  7. tar.gz文件命名和压缩解压方法

    tar.gz文件命名 tar这是文件打成一个包,无压缩; gz同gzip标记的包.tar文件压缩; 所以它成为一个.tar.gz档 压缩 # tar cvfz backup.tar.gz /xxx/ ...

  8. DataReader和DataSet的区别以及使用

    DataReader和DataSet这两个对象都可以将检索的关系数据存储在内存中.它们在功能使用方面非常相似,但是它们不可以相互替换. 主要区别如表所示:   DataReader DataSet 数 ...

  9. C#向并口设备发送指令以获取并口设备的状态

    using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Text; usi ...

  10. Otacle表查询

    1    查询表结构       语法:desc 表      2    查询全部列       语法:select * from 表名      3    查询指定列       语法:select ...