matlab secant method

matlab secant method

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

全栈程序员社区此处内容已经被作者隐藏,请输入验证码查看内容
验证码:
请关注本站微信公众号,回复“验证码”,获取验证码。在微信里搜索“全栈程序员社区”或者“www_javaforall_cn”或者微信扫描右侧二维码都可以关注本站微信公众号。

% 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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117900.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号