% 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. SMART rule之个人理解

    SMART原则通常应用于绩效评估中. S是specific的缩写,也就是你所设定的目标必须是一个具体的目标,而不是一个空而大的东西. 比如你的目标定位为今年学习linux,并对进程管理.内存管理等要能 ...

  2. kgdb接收一个数据包详解

    0    kdb>kgdb  // 可进入kgdb 模式    if (dbg_kdb_mode) {             error = kdb_stub(ks);     } else ...

  3. 屏幕对象的F1/F4输入帮助功能

    1.HELP-REQUST[FOR{LOW|HIGH}]字段的F1帮助 当选择SAP屏幕功能的制定字段按F1键时可以调关注用自定义的程序或者系统帮助文件,该功能通常称为F1帮助. TYPES:syst ...

  4. 小米手机usb共享网络mac

    今天.我想去FQgoogle,mac在墙上,不便于使用.甚至只是用Android手机wifi,打开墙软件.然后usb分享到mac.然后mac互联网. 在谈到一些复杂.其实,关键一,小米手机usb共享, ...

  5. URL加随机数的作用

    原文:URL加随机数的作用 大家在系统开发中都可能会在js中用到ajax或者dwr,因为IE的缓存,使得我们在填入相同的值的时候总是使用IE缓存,为了解决这个问题一般可以用一下方法:        1 ...

  6. 14.3.4 Phantom Rows 幻影行

    14.3.4 Phantom Rows 幻影行 所谓的幻读为发生在一个事务 当相同的查询产生不同的结果集在不同的时间. 比如,如果一个SELECT被执行2次, 但是第2次返回的记录不是第一次返回的记录 ...

  7. Java 开源博客——B3log Solo 0.6.1 正式版发布了!

    Java 开源博客 —— B3LOG Solo 0.6.1 正式版发布了!欢迎大家下载. 该版本主要是改善细节体验,并加入了一款 Metro 风格的皮肤. 特性 基于标签的文章分类 Ping Goog ...

  8. swfupload组件后台获取中文文件名称乱码的问题解决

       问题描写叙述:用swfupload上传文件,含有中文名称的文件上传会报错,我用的是获取FileItem对象,用FileItem对象的getName()方法获取文件名会乱码,试着用request. ...

  9. Python的经典问题——中文乱码

    关键字:Python UTF-8 GBK 中文 乱码 估计入门时都会遇到的.我是在windows下用的Python25自带的IDLE编辑运行的,发现运行脚本得出的结果有一些中文显示是乱码,但有一些是正 ...

  10. MySQL多表查询之外键、表连接、子查询、索引

    MySQL多表查询之外键.表连接.子查询.索引 一.外键: 1.什么是外键 2.外键语法 3.外键的条件 4.添加外键 5.删除外键 1.什么是外键: 主键:是唯一标识一条记录,不能有重复的,不允许为 ...