필터 지우기
필터 지우기

Error using input comand

조회 수: 3 (최근 30일)
sandy Fleming
sandy Fleming 2016년 3월 16일
댓글: Stalin Samuel 2016년 3월 17일
Hey
Im struggeling to use the input command when solving an equation using the Newton Raphson method. my whole code is as follow;
clear all
close all
clc
a=input((0.5)*x^3 -3*x^2 +3*x -4,'x');
x(1)=input(4);
error=input(1);
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)
when I enter;
  • a=input((0.5)*x^3 -3*x^2 +3*x -4,'x');
I recieve the following error;
  • Undefined function or variable 'x'.
If i define X before hand i recieve this error;
  • Error using inputThe first argument to INPUT must be a string.
if i use;
  • a=@(x) input((0.5)*x^3 -3*x^2 +3*x -4,'x');it brings up the same error but for the x(1) line
it would be very helpful to know why this happens and how to fix the code
thanks
sandy
  댓글 수: 1
Vaclav Rimal
Vaclav Rimal 2016년 3월 16일
What do you expect your first input command would return? The way you write your code does not make any sense; input takes just the string as an arguments.

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

답변 (1개)

Stalin Samuel
Stalin Samuel 2016년 3월 16일
  • Are you expecting like this
clear all
close all
clc
a='(0.5)*x^3 -3*x^2 +3*x -4';
x=input('Enter th x vector');%e.g[2 4 5 56 6 3]
error=input('Enter the error limit');%e.g 2
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)
  댓글 수: 3
sandy Fleming
sandy Fleming 2016년 3월 17일
Ive tried exactly what you said but i still get an error at the line
X=input(0.5 -3 3 -4)
the 3 is underlined in red with the error; unexpected matlab expression appearing in the command window.
Stalin Samuel
Stalin Samuel 2016년 3월 17일
X = [0.5 -3 3 -4] .no need to use the command input

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

카테고리

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