Use Matlab/Maple to find roots of a nonlinear equation

本小妞迷上赌 提交于 2019-12-13 20:15:13

问题


I am having difficulty in finding roots of a nonlinear equation. I have tried Matlab and Maple both, and both give me the same error which is

Error, (in RootFinding:-NextZero) can only handle isolated zeros

The equation goes like

-100 + 0.1335600000e-5*H + (1/20)*H*arcsinh(2003.40/H)

The variable is H in the equation.

How do I find the roots (or the approximate roots) of this equation?

Matlab Code: The function file:

function hor_force = horizontal(XY, XZ, Lo, EAo, qc, VA)
syms H
equation = (-1*ZZ) + (H/qc)*(cosh((qc/H)*(XZ- XB))) - H/qc + ZB;
hor_force = `solve(equation);`

The main file:

EAo = 7.5*10^7;
Lo = 100.17;
VA = 2002;

XY = 0;
ZY = 0;

XB = 50;
ZB = -2;

XZ = 100;
ZZ = 0;

ql = 40;

Error which Matlab shows:

Error using sym/solve (line 22)
Error using maplemex
Error, (in RootFinding:-NextZero) can only handle isolated zeros

Error in horizontal (line 8)
hor_force = solve(equation);
Error in main (line 34)
h = horizontal(XY, XZ, Lo, EAo, ql, VA)

http://postimg.org/image/gm93z3b7z/


回答1:


You don't need the symbolic toolbox for this:

First, create an anonymous function that can take vectors at input (use .* and ./:

equation = @(H) ((-1*ZZ) + (H./qc).*(cosh((qc./H).*(XZ- XB))) - H./qc + ZB);

Second, create a vector that you afterwards insert into the equation to find approximately when the sign of the function changes. In the end, use fzero with x0 as the second input parameter.

H = linspace(1,1e6,1e4);  
x0 = H(find(diff(sign(equation(H)))));  %// Approximation of when the line crosses zero
x = fzero(equation, x0)  %// Use fzero to find the crossing point, using the initial guess x0
x =    
   2.5013e+04
equation(x)
ans =
     0

To verify:

You might want to check out this question for more information about how to find roots of non-polynomials.




回答2:


In Maple, using the expression from your question,

restart:

ee := -100 + 0.1335600000e-5*H + (1/20)*H*arcsinh(2003.40/H):

Student:-Calculus1:-Roots(ee, -1e6..1e6);

            [               5                           ]
            [-1.240222868 10 , -21763.54830, 18502.23816]

#plot(ee, H=-1e6..1e6, view=-1..1);


来源:https://stackoverflow.com/questions/27180826/use-matlab-maple-to-find-roots-of-a-nonlinear-equation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!