function [ Xs ] = RegulaRaiz( Fun,a,b,ErrMax )
imax=100;
Fa= Fun(a)
Fb=Fun(b)
The code for fun is:
function y = Fun(x)
y = (sin(x)/(3*x))-0.25;
end
If I call the function as RegulaRaiz( 'Fun',1,2,0.0001 )
Fa becomes f and fb becomes u, how do i fix this?

 채택된 답변

michio
michio 2016년 9월 21일

3 개 추천

The first input 'Fun' to the function RegulaRaiz is 1x3 char, 'Fun'. So Fa = Fun(1) is f and, Fb = Fun(2) = u.
Could you try
RegulaRaiz(@(x) Fun(x),1,2,0.0001)
instead? Specify the function as an input using a function handle @(x) Fun(x).

댓글 수: 2

Vitor Braz
Vitor Braz 2016년 9월 21일
Thank you!
Or simpler and faster:
RegulaRaiz(@Fun,1,2,0.0001)

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

추가 답변 (1개)

Adam
Adam 2016년 9월 21일
편집: Adam 2016년 9월 21일

1 개 추천

Why are you naming a variable passed to your function the same as a function? The string you pass in as the variable 'Fun' is hiding the function so
Fa= Fun(a);
is trying to index into 'Fun' so Fun(a) is Fun(1) which is 'F' and Fun(b) is Fun(2) which is 'u'.

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

질문:

2016년 9월 21일

편집:

2016년 9월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by