# Beginner in matlaB i need lil help

1. Oct 2, 2009

### Casablanca

hello everyBody..
am a beginner in matlab i need lil help in the equation blew.. and if anyone has any tutorial for matlab i'll b more than welcome to accept them :P

y=e^x . cos x

plot : pi greater than x greater than 0
then plot : -pi smaller than x smaller than one

then combine the two graphs

i tried to do it but i get alot of errors,,

my trial :
x=0:pi;
y=exp(x)* cos(x)
subplot (3,1,1)
plot (x,y)

x1=-pi:0;
y1=exp(x)* cos(x)
subplot (3,1,2)
plot (x1,y1)

subplot(3,1,3)
plot (y,y1)

=S

2. Oct 2, 2009

### ApexOfDE

Your problem is that: in the first line, you declare x as an array. In the second line, you force matlab to calculate the exp and cos value for each member of x array. Therefore, matlab throws error because exp and cos funtion in matlab dont know how to do that but they only accept 1 value for argument per calculations.. To avoid this problem, you should use loop. For example:

Code (Text):
x=0:0.01:pi;

for j = 1 : length(x)              // for loop
y=exp(x(j))* cos(x(j));     // pick member x(j) to calculate
end;

plot (x,y)
//x(A) will give you value of Ath member of array x (A is integer and smaller than size of x).

----------
Loop is crucial concept for programming that you must obtain, such as FOR loop, WHILE loop, DO loop.