필터 지우기
필터 지우기

Conversion to logical from sym is not possible? please help

조회 수: 2 (최근 30일)
Abdurahman Itani
Abdurahman Itani 2017년 9월 25일
댓글: Walter Roberson 2017년 9월 25일
I am trying to build a newton raphson program to solve nonlinear equations. this is the function. for some reason i cant get it to work.
% Program Code of Newton-Raphson Method in MATLAB
a=input('Enter the function in the form of variable x:','s');
x(1)=input('Enter Initial Guess:');
error=input('Enter allowed Error:');
f=inline(a)
dif=diff(sym(a));
d=inline(dif);
for i=1:100
x(i+1)=x(i)-((f(x(i))/d(x(i))));
err(i)=abs((x(i+1)-x(i))/x(i));
if err(i)<error
break
end
end
root=x(i)
here is my script to call the function
where i recieve the error message.
syms x
y =@(x)(exp((x-2)^2)-2);
%dy = diff(y(x));
hello(y,0,0.001)

답변 (1개)

Walter Roberson
Walter Roberson 2017년 9월 25일
Using inline() is not recommended unless you are stuck at MATLAB 5.0 or earlier. Use matlabFunction() instead for this case.
  댓글 수: 2
Abdurahman Itani
Abdurahman Itani 2017년 9월 25일
what does matlabfunction() do ? how can I use it?
Walter Roberson
Walter Roberson 2017년 9월 25일
"g = matlabFunction(f) converts the symbolic expression or function f to a MATLAB® function with handle g. The function can be used without Symbolic Math Toolbox™."

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

카테고리

Help CenterFile Exchange에서 Newton-Raphson Method에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by