简体   繁体   English

在matlab中求解超越方程

[英]Solving transcendental equation in matlab

Looking for help solving transcendental equations in Matlab.寻求在 Matlab 中求解超越方程的帮助。 Here's an equation for example:例如,这里有一个等式:

1/2 = cos(x)cos(2x) ; 1/2 = cos(x)cos(2x) ; 0<=x<=pi/2 solving for x: 0<=x<=pi/2 求解 x:

x = acos((1/2)(sec(2x)) x = acos((1/2)(sec(2x))

I have tried using intersect() along with various other Matlab functions.我曾尝试将 intersect() 与其他各种 Matlab 函数一起使用。 It's easy to see an approximate value of ~.48 when I plot using the following code:当我使用以下代码绘图时,很容易看到 ~.48 的近似值:

x = 0:(pi/2)/1000:pi/2;
f = @(x) (1/2)*acos((1/2)*sec(x));
plot(x,f(x));

How can I have Matlab return the value where x == f(x) within a certain tolerance?我怎样才能让 Matlab 在某个容差范围内返回 x == f(x) 的值?

For finding a numerical solution it doesn't really matter if you have a polynomial or even a transcendental equation.为了找到数值解,是否有多项式甚至超越方程并不重要。 In general for your particular problem there are two nice built-ins: fzero tries to find a root of a function f , that is a value x where f(x) == 0 .一般来说,对于您的特定问题,有两个很好的内置函数: fzero尝试找到函数f的根,即值x ,其中f(x) == 0 You need to provide an initial estimate but you cannot provide bounds.您需要提供初始估计值,但不能提供界限。 Then there is fminbnd which minimizes your function, so you have to write your problem as a minimization problem .然后是fminbnd最小化你的函数,所以你必须把你的问题写成一个最小化问题 But in this case you can provide bounds:但在这种情况下,您可以提供界限:

format long
% find a root (unbounded)
f=@(x)1/2 - cos(x).*cos(2*x);
z = fzero(f,0,optimset('TolX',1e-5));
disp(z);

% find a minimum (bounded)
g=@(x)(f(x)).^2;
z = fminbnd(g,0,pi/2,optimset('TolX',1e-5));
disp(z);

Try it online! 在线试试吧!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM