% 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

最新文章

  1. EntityFramework之监听者判断SQL性能指标
  2. failed to load the jni shared library jvm
  3. Android初级教程_获取Android控件的宽和高
  4. ecshop2.72文件结构说明
  5. 看京东如何把Intel RealSense技术用在物流上
  6. Adapter模式
  7. js复制button在ie下的解决方式
  8. (转)Java中使用正则表达式的一个简单例子及常用正则分享
  9. Splay的初步学习
  10. python 列表复制给另一个列表,改值两个列表均会改变(备忘)
  11. 一元二次方程解法的实现(Python)
  12. Ionic命令大全
  13. 023 Hadoop的生态系统
  14. Spring Boot中启动HTTPS
  15. BZOJ4868 [Shoi2017]期末考试 【三分 + 贪心】
  16. CROC 2016 - Qualification B. Processing Queries 模拟
  17. WCF 之 数据契约
  18. 工作表(Worksheet)基本操作应用示例
  19. 关于SQL优化这些你了解吗?
  20. LTE QCI分类 QoS

热门文章

  1. Nginx 訪问日志增长暴增出现尖刀的具体分析
  2. J2EE开发框架搭建(1) - maven搭建多项目
  3. 谁说程序员都是苦逼的——看看兄弟连上海S2班的点点滴滴
  4. 邮件应用Acompli和日历应用Sunrise(传微软曾考虑以80亿美元收购企业通讯公司Slack)
  5. 让Android中的webview支持页面中的文件上传
  6. Java编码浅析(注意区分三个概念)(转)
  7. RT3070 USB WIFI 在连接socket编程过程中问题总结
  8. codeforces 577
  9. Otacle表查询
  10. Android 结合实例学会AsyncTask的使用方法