Function index is a string, why?
显示 更早的评论
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?
采纳的回答
更多回答(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 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!