I am trying to plot f(x)= 1/(1+25x^2) but am getting the error: File: drafts.m Line: 2 Column: 18
Invalid expression. When calling a function or indexing a variable,
use parentheses. Otherwise, check for mismatched delimiters.
x=linspace(-1,1,11);
y=(1/(1+(25*x^2));
plot(x,y)
if i change line 2 to y=sin(x) this works so why does this not work in this instance?

답변 (1개)

James Tursa
James Tursa 2020년 4월 23일
편집: James Tursa 2020년 4월 23일

0 개 추천

Error message says to check for mismatched delimiters. So this
y=(1/(1+(25*x^2));
should be this with one fewer paren:
y=1./(1+(25*x.^2));
The / and ^ were changed to the element-wise operators ./ and .^ so that your function is "vectorized" and will work with arrays.

댓글 수: 2

Ryan Ferrell
Ryan Ferrell 2020년 4월 23일
i understand why there needs the be an x. I forgot to write that in the question but why does "1" need to be "1."?
James Tursa
James Tursa 2020년 4월 23일
I am not changing x to x. and 1 to 1.
I am changing / to ./ and ^ to .^
That is, the dots get attached to the operators / and ^, not to the operands 1 and x
The element-wise operators ./ and .^ are DIFFERENT operators from the matrix operators / and ^

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

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2020년 4월 23일

댓글:

2020년 4월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by