Why am I getting error "Array indices must be positive" and error in syms, when using eval function
조회 수: 1 (최근 30일)
이전 댓글 표시
Why am I getting errors when using the eval function?
syms x
f(x) = 3.5*x*(1-x)
f2 = f(f(x))
eqn2 = f2 == x;
sol= (solve(eqn2,x))
eval(f2(sol(2)))
I have used the same steps to evaluate f with no errors.
Any pointers would be really appreciated.
댓글 수: 1
Stephen23
2022년 2월 10일
편집: Stephen23
2022년 2월 10일
"Why am I getting errors when using the eval function? "
Because EVAL is completely the wrong tool for the job.
Note that EVAL is not listed anywhere in the Symbolic Toolbox documentation: https://www.mathworks.com/help/symbolic/referencelist.html?type=function
The correct use of EVAL is with MATLAB code, not with objects from the Symbolic Math Toolbox:
채택된 답변
Highphi
2022년 2월 9일
I think it's because you need to make f, f2, and eqn2 functions of x (even though I drop eqn2)
syms x f f2 % << here
f(x) = 3.5*x*(1-x) % and see f(x) instead of just f
f2(x) = f(f(x)) % etc
% eqn2(x) = f2(x) == x %% not necessary
% sol = solve(eqn2, x) %% not necessary
sol = solve(f2(x) == x, x)
eval(f2(sol(2)))
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!