# How to get z for different x

조회 수: 2(최근 30일)
Atom 18 Dec 2012
x = [-2:0.1:2];
z=x.*(1-x).*(2-x).*(4-x)/((6-x)-(1-x).*(x-7));
I am getting error. Please correct my problem.

#### 댓글 수: 2

Thomas 18 Dec 2012
what error are you getting? what answer do you expect?
Atom 18 Dec 2012
There are 41 values of x and for each x I need one z. I am not getting this. I am getting only one value of z (=-2.1203).

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

### 채택된 답변

Wayne King 18 Dec 2012
편집: Wayne King 18 Dec 2012
x = [-2:0.1:2];
z = x.*(1-x).*(2-x)./((6-x).*(x-7));
You just forgot a ./
Now you should have a vector
x = [-2:0.1:2];
z = x.*(1-x).*(2-x)./((6-x).*(x-7));
plot(x,z)

#### 댓글 수: 1

Atom 18 Dec 2012
Yes. Thanking you.

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

### 추가 답변(2개)

Thomas 18 Dec 2012
x = [-2:0.1:2];
z=x.*(1-x).*(2-x).*(4-x)./((6-x)-(1-x).*(x-7))
You missed the . before the division to do element by element division

#### 댓글 수: 0

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

Daniel Shub 18 Dec 2012
Presumably you want to use ./ instead of /, just like you are using .* instead of *

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

### Community Treasure Hunt

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

Start Hunting!

Translated by