How do I find the zeros of my function?

Jogn20522 deleted the question after it was answered, so I (MF) am restoring it from memory.
How do I find all the zeros of this function?
ezplot('2*x.^4-3*x.^2+x-7')

댓글 수: 2

Matt J
Matt J 2012년 10월 7일
편집: Matt J 2012년 10월 7일
Since it's a polynomial, why not use ROOTS?
If it won't always be a polynomial, you need to at least know a priori the minimum spacing between the zeros, and preferably also a tighter bound on the number of them in a given interval. Do you know any general traits of the function that could be used to derive this info?
Matt Fig
Matt Fig 2012년 10월 7일
Pleas do not destroy this question be deleting it and asking a new question in its place! Restore this question, then ask a follow-up question either by posting a comment or by opening a whole new question.

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

 채택된 답변

Matt Fig
Matt Fig 2012년 10월 7일
편집: Matt Fig 2012년 10월 7일

1 개 추천

Here is a simpler approach:
x = (-2:0.01:2);
y = @(x) 2*x.^4-3*x.^2+x-7;
plot(x,y(x)); hold on;
cnt = 1;
for ii = -2:.5:2;
rt(cnt) = fzero(y,ii);
cnt = cnt + 1;
end
rt = unique(round(rt*1e10)/1e10);
plot(rt,zeros(size(rt)),'or')

댓글 수: 1

Matt Fig
Matt Fig 2012년 10월 7일
편집: Matt Fig 2012년 10월 8일
In general, one would put the call to fzero in a try-catch block because it can error....

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

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 10월 7일
편집: Andrei Bobrov 2012년 10월 7일

0 개 추천

x = (-2:0.01:2);
f = @(x)2*x.^4-3*x.^2+x-7;
d = f(x);
[a, i1] = findpeaks(d);
[b, i2] = findpeaks(-d);
b = -b;
p = [d(1),1;sortrows([[a; i1],[b; i2]]',2);d(end),numel(d)];
ii = p([true;diff(p(:,1) > 0) ~= 0],2);
for jj = numel(ii):-1:2
rootn(jj-1) = fzero(f,[x(ii(jj-1)),x(ii(jj))]);
end
plot(x,f(x),'b-',rootn,f(rootn),'ro'),grid on
%as the Matt Fig answer
x = (-2:0.01:2);
f = @(x)2*x.^4-3*x.^2+x-7;
[a, i1] = findpeaks(f(x));
x0 = [1;i1(:);numel(x)]
root1 = unique(arrayfun(@(ii)fzero(f,x(ii)),x0));

카테고리

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

질문:

2012년 10월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by