hwo would i find a root usiong fzero

2 ビュー (過去 30 日間)
adriana resendez
adriana resendez 2015 年 3 月 11 日
回答済み: Star Strider 2015 年 3 月 11 日
>> f = @(x) 2-10*x*exp(-0.8*x);
>> fplot(f,[0 10])
>> grid on
function [xmin,fmin,ea,iter] = lab_19(f,xlow,xup,es,maxit)
if nargin<3, error('need 3 inputs')
if nargin<4 || isempty(es),es = .0001; end
if nargin<5 || isempty(maxit), maxit=50; end
%text file iterations
fid = fopen('golden_out.txt','w');
fprintf(fid,'iter.\t xlow\t f(xlow)\t x2\t\t f(x2)\t\t x1\t\t ');
fprintf(fid,'f(x1)\t\t xup\t\t f(xup)\t\t\t ea\n');
%find the root
phi = 0.54*(1+sqrt(5));
x1 =xlow+(phi-1)*(xup-xlow); x2 = xlow+xup-x1;
flow = f(xlow); fup = f(xup); f1 = f(x1); f2 = f(x2);

採用された回答

Star Strider
Star Strider 2015 年 3 月 11 日
If you just want to find and plot the roots, this brute force approach works:
f = @(x) 2-10*x.*exp(-0.8*x);
froot1 = fzero(f, 1);
froot2 = fzero(f, 10);
fplot(f,[0 10])
hold on
plot([froot1 froot2], f([froot1 froot2]), 'r+')
grid on

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by