I have a problem with this code:
When i give in input this:
fzer0(@(x)x.^2-4,[0 4])
Matlab give me a good plot.
When i give in input this:
fzer0(@(x)x.^2-4,[0 13])
Matlab give me a wrong plot, the output have not a plot!!
plot(fun(xo(1):0.00001:xo(2)), 'b - ', 'LineWidth', 2.5);
grid on;
yline(0, '--r', 'y = 0');
xlabel('x');
str=func2str(fun); %stringa della funzione
newstr=erase(str(5:end), '.'); %cancella dall'espressione il function handle e cancella il punto
tit=strcat('f = ', newstr);
title(tit);
text(double(m), double(0), strcat( 'x = ', num2str(m) ) );
set(gcf, 'color', 'g');
set(gca, 'FontSize', 9);

댓글 수: 3

Walter Roberson
Walter Roberson 2019년 4월 2일
I am not clear what fun is here?
Also we have no information about xo(1) and xo(2) ?
Fun is a function that in the 2 case is x^2-4.
this is the code for xo(1) and xo(2):
while(abs(diff(xo))>= p.Results.TOL*max(abs(xo)) && abs(fun(m))>TOLF && nit<p.Results.NMAX)
if(fun(m)*fun(xo(1))<0)
xo(2)= m;
else
xo(1)= m;
end
nit=nit+1;
m = xo(1)+0.5*diff(xo);
end
if(abs(diff(xo))> p.Results.TOL*max(abs(xo)) && abs(fun(m))>TOLF && nit==p.Results.NMAX)
warning("limit reached... calculation stop! ");
end
x=m;
output.fx = fun(x);
output.niter = nit;
Walter Roberson
Walter Roberson 2019년 4월 3일
Please put everything together in a form that we can run, in order to test your code.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Clocks and Timers에 대해 자세히 알아보기

태그

질문:

2019년 4월 2일

댓글:

2019년 4월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by