I'm trying to find all the points between 0 and 10 where the derivative of y=0 by using (x1(H)+x2(H))/2) as a staring point but I keep on getting this error... Please help :(
Error using fzero (line 169) If FUN is a MATLAB object, it must have an feval method.
h=10;
ti=(1/200);
n=[1.2 2.9];
ni=[1 3];
na=[2 1];
x=[];
for k=1:numel(n)
x=sort([x (((0:1:1+(ceil(h/(n(k)))))-0.5)*(n(k)))]);
end
x1=(x(1:numel(x)-1));
x2=(x(2:numel(x)));
for T=[1:10];
nwa=[na.*sin((T*ti)*(pi./(ni)))];
for H=(1:numel(x1))
syms d;
y=sum(nwa.*cos(d.*(pi./n)));
X(H)=fzero(diff(y),(x1(H)+x2(H))/2);
end
P=(X(X>x1<x2))';
end

 채택된 답변

dpb
dpb 2013년 10월 20일

0 개 추천

From the doc's for fzero
X = fzero(FUN,X0) ... FUN is a function handle.
Your code is
X(H)=fzero(diff(y),(x1(H)+x2(H))/2);
where you've entered an actual function.

댓글 수: 4

Tristan
Tristan 2013년 10월 20일
I can't figure out how to apply that though...
dpb
dpb 2013년 10월 20일
Well, it's not clear to me what your function is intended to be solving but the basic idea is to write a function either as an anonymous function or give the handle to an existing function and an initial guess and the fzero will find the value that provides a zero to that function on the assumption a zero-crossing can be found near (for some definition of near) x0.
Clarify what it is you're trying to get fzero to do for you here...
Tristan
Tristan 2013년 10월 20일
I'm trying to find a way to calculate the position of the antinodes (the maximas and minimas) of a waveworm=sum(nwa.*cos(d.*(pi./n))) by using its derivative, and then using fzero starting at all the midpoints between consecutive multiples of n between 0 and 10.
dpb
dpb 2013년 10월 21일
There's an example in the doc on fzero using trig functions for formulation that should be illustrative.

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

추가 답변 (0개)

카테고리

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

태그

질문:

2013년 10월 20일

댓글:

dpb
2013년 10월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by