Passing functions in MATLAB
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Hi I am having some difficulty passing functions on MATLAB and needed some help.
I am trying to implement a bisection algorithm, [l,r,nf] = bisect ( fname, a,b, tol)
Where l and r are the left and right handed end-points of the root-bracketing interval, and fname is another M-file in my directory that contains the actual function being evaluated (also an M-file)
How does one use a function as the input for an argument in MATLAB? Thanks!
댓글 수: 0
답변 (1개)
dpb
2018년 10월 3일
0 개 추천
Look at function handles; there's a section under Data Types in the documentation...
댓글 수: 2
Shakil Rafi
2018년 10월 4일
Walter Roberson
2018년 10월 4일
function [l,r,nf] = bisect ( fname, a, b, tol)
if fname(a) * fname(b) > 0
[...]
To be called with something like
[left, right, count] = bisect( @(x) sin(x).^2 - tan(x), -pi/2, pi/2, 0.01 )
이 질문은 마감되었습니다.
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!