## problem in creating an array

süleyman burak çelik

### süleyman burak çelik (view profile)

님이 질문을 제출함. 15 Jan 2015
최근 활동 süleyman burak çelik

### süleyman burak çelik (view profile)

님이 댓글을 추가함. 17 Jan 2015
Youssef Khmou

### Youssef Khmou (view profile)

님이 답변을 채택함.
I have a simple problem, but I can't solve. I created an array naming as "alfas" given below. When the numbers of variables is more than one and when the code is run, in the command window, lz is an array, but alfas gives only one alfas value:
below code gives an array for alfas, there is no problem: clc; clear; clear all; lamda=0.1; k=2*pi/lamda; rho=3*lamda; a=0.5; e=3; fis=-pi:pi./100:pi; alfas=(acos((e.*cos(fis)-1)/(sqrt(e.^2-2.*e.*cos(fis)+1)))); alfas In command window, alfas is an array. it is OK.
But, when the code below is run, alfas gives only one result in command window:
clc; clear; clear all; lamda=0.1; k=2*pi/lamda; rho=3*lamda; a=0.5; e=3; fis=-pi:pi./100:pi; lz=((a.*(e.^2-1))./(e.*cos(fis)-1)); alfas=(acos((e.*cos(fis)-1)/(sqrt(e.^2-2.*e.*cos(fis)+1))));
lz % it is an array , alfas % it gives only one result that is equal to 2.0495
in Command window, alfas=2.0495 (only one result)
Why cannot I see an array for alfas in this situation, I cannot understand. If anybody could help me, I will be very happy. Thank you very much.

로그인 to comment.

## 답변 수: 1

Youssef Khmou

### Youssef Khmou (view profile)

님의 답변 15 Jan 2015
채택된 답변

The reason the output is scalar is because you divide a vector by vector like in this example rand(1,4)/rand(1,4), to return an array you need to use element wise operation rand(1,4)./rand(1,4), to fix this problem in your example try :
alfas=(acos((e.*cos(fis)-1)./(sqrt(e.^2-2.*e.*cos(fis)+1))));

#### 댓글 수: 1

süleyman burak çelik

### süleyman burak çelik (view profile)

17 Jan 2015
Upsss! Thank you very much.. I supposed that I added dot(.) everywhere in the equation, but you showed me that I missed dot (.) there... Thank you very much again.

로그인 to comment.

Translated by