problem in creating an array

2 vues (au cours des 30 derniers jours)
süleyman burak çelik
süleyman burak çelik le 15 Jan 2015
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.

Réponse acceptée

Youssef  Khmou
Youssef Khmou le 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 commentaire
süleyman burak çelik
süleyman burak çelik le 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by