### Translated by

이 페이지의 내용은 영어에서 자동 번역되었습니다. 자동 번역 기능을 해제하려면 "<a class="turn_off_mt" href="#">여기</a>"를 클릭하십시오.

## how to add a matrix element in a fzero function

Asked by ekrem yilmaz

### ekrem yilmaz (view profile)

on 14 Apr 2019
Latest activity Commented on by dpb

### dpb (view profile)

on 14 Apr 2019
Accepted Answer by dpb

### dpb (view profile)

Hi guys,
i m trying to solve x*besselj(1,x)/besselj(0,x)-J(m) using fzero function
My code is
n = 100;
J = [0.5 2 5 10 20 30 50 100];
for i = 1:n
A(i,1)=fzero('x*besselj(1,x)/besselj(0,x)-J(1)',i);
end
for i = 1:n
A(i,2)=fzero('x*besselj(1,x)/besselj(0,x)-J(2)',i);
end
for i = 1:n
A(i,3)=fzero('x*besselj(1,x)/besselj(0,x)-J(3)',i);
end
for i = 1:n
A(i,3)=fzero('x*besselj(1,x)/besselj(0,x)-J(4)',i);
end
for i = 1:n
A(i,3)=fzero('x*besselj(1,x)/besselj(0,x)-J(5)',i);
end
for i = 1:n
A(i,3)=fzero('x*besselj(1,x)/besselj(0,x)-J(6)',i);
end
for i = 1:n
A(i,3)=fzero('x*besselj(1,x)/besselj(0,x)-J(7)',i);
end
for i = 1:n
A(i,3)=fzero('x*besselj(1,x)/besselj(0,x)-J(8)',i);
end
i am trying to write the code above
n = 100;
J = [0.5 2 5 10 20 30 50 100];
for j = 1:8
for i = 1:n
A(i,m)=fzero('x*besselj(1,x)/besselj(0,x)-J(m)',i);
end
end
like that. when i run the code i get this error;
Error using fzero (line 306)
FZERO cannot continue because user-supplied expression ==> x*besselj(1,x)/besselj(0,x)-J(m) failed with the error below.
Error in inline expression ==> x*besselj(1,x)/besselj(0,x)-J(m)
Undefined function or variable 'm'.
Error in Untitled (line 6)
A(i,m)=fzero('x*besselj(1,x)/besselj(0,x)-J(m)',i);
Can you help to solve this.
Thanks

### dpb (view profile)

on 14 Apr 2019

As you wrote it, the function is the literal text including the argument so nothing ever gets substituted for dynamically--one way that mimics yours directly but does get the current value of J() would be
...
for i = 1:n
fnA=@(x) x*besselj(1,x)/besselj(0,x)-J(i);
A(i,n)=fzero(fnA,0);
end
that embeds current J(i) into the function handle.
I just used a constant zero for the initial guess, that worked for the first couple; I didn't check if need better for the full range...