% 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. 单片机C语言实现的采用DS18B20的温度检测装置

    这几天老师布置了一个课程设计题目:采用51单片机控制的DS18B20温度检测系统.大概花了我一个礼拜的时间,幸好我的C语言学得还可以,最后还是让我搞出来了,真是高兴,我是采用STC-52单片机和DS1 ...

  2. Phpcms V9 所有的中文变量

    $LANG['start_update_category'] = '开始更新栏目页 ...'; $LANG['start_to_end_id'] = '" 第{page} - {endpag ...

  3. [置顶] ※数据结构※→☆线性表结构(queue)☆============循环队列 顺序存储结构(queue circular sequence)(十)

    循环队列 为充分利用向量空间,克服"假溢出"现象的方法是:将向量空间想象为一个首尾相接的圆环,并称这种向量为循环向量.存储在其中的队列称为循环队列(Circular Queue). ...

  4. 450A - Jzzhu and Children 找规律也能够模拟

    挺水的一道题.规律性非常强,在数组中找出最大的数max,用max/m计算出倍数t,然后再把数组中的书都减去t*m,之后就把数组从后遍历找出第一个大于零的即可了 #include<iostream ...

  5. IDL 自己定义功能

    function add,x,y return, x+y end pro sum x=1 y=2 print,add(x,y) end 版权声明:本文博客原创文章,博客,未经同意,不得转载.

  6. 例3.1 猜猜数据结构 UVa11995

    1.标题叙述性说明:点击打开链接 2.解题思路:据来推測一种可能的数据结构,备选答案有"栈,队列.优先队列".结果也可能都不是或者不确定. STL中已经有这三种数据结构了,因此直接 ...

  7. POJ 3040 Allowance 贪心

    这题目的贪心思路还是有一点细节问题的. 还没有证明,据说是因为题目给的条件是每个价格是比它小的价格的倍数才能这么贪心的. 思路如下: 假设要给奶牛的钱为C 1)从大面值到小面值一次拿钱,能拿多少拿多少 ...

  8. iOS学习——iOS国际化(十二)

    开发的移动应用更希望获取更多用户,走向世界,这就需要应用国际化,国际化其实就是多语言.这篇文章介绍Xcode4.5以后的国际化,包括应用名国际化和应用内容国际化.如果是Xcode4.5之前版本请参考. ...

  9. Android架构设计和软硬整合完整训练

    Android架构设计和软硬整合完整训练 Android架构设计和软硬整合完整训练:HAL&Framework&Native Service&Android Service&a ...

  10. Visual Leak Detector(vld)无法显示内存泄露文件名称与行号

    使用VLD測有没内存泄露的时候,出现(File and line number not available): (Function name unavailable) 查看VS控制台,发现 已载入&q ...