2015-01-31 444 views
-4

如果有人可以幫助我在matlab中回答以下問題,將不勝感激,我是新來的軟件,我很困惑。Matlab fzero函數

使用fzero近似的sin(x)的根= COS(2個)近X = 1

回答

2

的fzero函數期望得到的功能手柄和一個起點。它的結果是作爲函數根的最近點。在你的情況下,我們正在尋找在x = 1附近的cos(2x)-sin(x)= 0的根。你需要的代碼是:

fun = @(x)(cos(2*x)-sin(x)); % Create an anonymous function handle. 
x0 = 1;      % Set a starting point. 
res = fzero(fun, x0);  % Calculate the nearest root. 
0

你的問題相當於找到一個函數的零點:

f=cos(2.*x)-sin(x) 

首先,f創建新的函數文件:

function y = funczero01(x) 
%Finding the zeros of the function below 
y=cos(2.*x)-sin(x); 

endfunction 

保存文件與funczero01.m並加載它的路徑。 然後在調試器窗口調用funczero01

x0=fzero('funczero01',1) 
x0 = 0.52360 

確保你真正瞭解fzero('func',x0)。欲瞭解更多詳情,請查看Matlab文檔