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
matlab secant method的更多相关文章
- Secant Method (Website)
Secant Method: https://www.youtube.com/watch?v=qC9xnsfOd30 Secant Method : http://mathworld.wolfram ...
- matlab Newton method
% Matlab script to illustrate Newton's method % to solve a nonlinear equation % this particular scri ...
- The Secant Method(正割法、弦截法) 附C语言代码
弦截法是一种求方程根的基该方法,在计算机编程中经常使用. 他的思路是这种:任取两个数x1.x2,求得相应的函数值f(x1).f(x2).假设两函数值同号,则又一次取数.直到这两个函数值异号为止. 连接 ...
- Todd's Matlab讲义第6讲:割线法
割线法 割线法求解方程\(f(x)=0\)的根需要两个接近真实根\(x^\*\)的初值\(x_0\)和\(x_1\),于是得到函数\(f(x)\)上两个点\((x_0,y_0=f(x_0))\)和\( ...
- 牛顿方法(Newton-Raphson Method)
本博客已经迁往http://www.kemaswill.com/, 博客园这边也会继续更新, 欢迎关注~ 牛顿方法是一种求解等式的非常有效的数值分析方法. 1. 牛顿方法 假设\(x_0\)是等式的 ...
- 非线性方程(组):一维非线性方程(二)插值迭代方法 [MATLAB]
一般而言,方程没有能够普遍求解的silver bullet,但是有几类方程的求解方法已经非常清晰确凿了,比如线性方程.二次方程或一次分式.一次方程可以直接通过四则运算反解出答案,二次方程的求根公式也给 ...
- Secant 方法求方程多个根
Secant 方法介绍 Secant Method 函数 Secant_Methods 简介 1.函数定义 [c, errColumn] = Secant_Method(f, a, b, N, con ...
- <<Numerical Analysis>>笔记
2ed, by Timothy Sauer DEFINITION 1.3A solution is correct within p decimal places if the error is l ...
- <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 ...
随机推荐
- 一个解析RTSP 的URL函数
写了一个解析URL的函数,可以提取URL中的IP 和 port. 如:url = "rtsp://192.168.1.43:2554/realmp3.mp3"; url = &qu ...
- SQL--存储过程+触发器 对比!
一.存储过程 一:存储过程:存储过程是一组为了完成特定功能的SQL 语句集,经编译后存储在数据库中. 可以用存储过程名字和参数来调用存储过程,这样可以避免代码重复出现,用起来也方便. 例: 下面 ...
- openCV之头文件分析
我们利用openCV开源库进行项目开发时,往往要牵涉到头文件的添加问题,而openCV中头文件众多,该如何选择呢?下面对openCV2.4.10的头文件进行一个简单的梳理,以便能够快速的添加对应的头文 ...
- 如何使用git
本文不是谈论git具体命令的技术文章. 原文地址:http://blog.csdn.net/ffb/article/details/11206067 我之前发了一条关于git中如何处理中文文件名的微博 ...
- zoj 3870
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5518 题意:n个数,从中选出两个数,问这两个数的异或值大于两个数较大 ...
- 14.4.2 Configuring InnoDB for Read-Only Operation 配置InnoDB 永于只读操作:
14.4.2 Configuring InnoDB for Read-Only Operation 配置InnoDB 永于只读操作: 你可以查询InnoDB 表 MySQL 数据目录是在只读介质里,通 ...
- Zero Clipboard - 跨浏览器兼容的“复制到剪贴板”功能
开发中经常会用到复制的功能,在 IE 下实现比较简单,但要想做到跨浏览器比较困难了. 本文将介绍一个跨浏览器的库类 Zero Clipboard ,它利用 Flash 进行复制,所以只要浏览器装有 F ...
- 安装Oracle JDK 7.0与8.0 for Mac OS X后Eclipse启动报错的解决之道
启动 Eclipse 时,直接报错The JVM shared library "/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Cont ...
- java中clone的深入理解
Java中Clone的概念大家应该都很熟悉了,它可以让我们很方便的“制造”出一个对象的副本来,下面来具体看看java中的Clone机制是如何工作的? 1. Clone和Copy 假 ...
- SPOJ DISUBSTR(后缀数组)
传送门:DISUBSTR 题意:给定一个字符串,求不相同的子串. 分析:对于每个sa[i]贡献n-a[i]个后缀,然后减去a[i]与a[i-1]的公共前缀height[i],则每个a[i]贡献n-sa ...