# Hi, I have set of values for x (x = 1:10) and I have a equation y = x^(1/2)/x, how can i get and display an array of values of y from the x's ?

조회 수: 1(최근 30일)
Gurinder Punni 2020년 1월 31일
댓글: ME 2020년 2월 3일
All i get is one number, when i should be getting a array of y values.
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Gurinder Punni 2020년 1월 31일
x = 1:10;
y = x.^(1/2)./x
fprintf(' %.2f \n', y)
this is my code

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

### 답변(1개)

ME 2020년 1월 31일
I don't know how you've got one number but I think you should be using:
x = 1:10
y = x.^(1/2)./x
##### 댓글 수: 3표시숨기기 이전 댓글 수: 2
ME 2020년 2월 3일
As Star Strider says, thius is the difference between array and matrix operations - i.e. do you want the operation to perform as if your inputs are matrices or not.
If you starts with
A=[2 2 2;2 2 2;2 2 2]
B=[3 3 3;3 3 3;3 3 3]
then A*B will perform a matrix multiplication and give:
A*B
ans =
18 18 18
18 18 18
18 18 18
whereas A.*B will do an array operation and calculate element-wise to give:
A.*B
ans =
6 6 6
6 6 6
6 6 6
Can I also please request that if this answer was of help to you that you accept my answer.

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

### 범주

Find more on Loops and Conditional Statements in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!