% Assignment #2
% Problem #1
t=[0:0.1:10];       % Colon notation: starting value: increment: ending value
x1=2.*exp(-t);      % If we put 1-2.*exp(-t) we will get increasing exponential,
                    % we will put 1-2.*exp(-t) later to get the desire decay exponential
x2=sin(t);
x=1-(x1.*x2);       %Here we take 1 minus the rest of the function that we want to plot
plot(t,x),grid on;  %plot x versus t
xlabel('Time');ylabel('Amplitude');title('Problem #1-Decaying-Oscillating Exponential')

*******************************************************************************************
%Problem #2         
t=[0:0.5:25];      % Colon notation: starting value: increment: ending value 
y1=1.25*exp(-t);   
y2=2.02*exp(-0.3*t);

%graph both functions on same graph
plot(t,y1,t,y2,'y'), grid on, legend ('1.25*exp(-t)','2.02*exp(-0.3*t)');
Limit=[0,16,-1,1]; axis(Limit); %set the limit for the function
title ('Problem #2 Part A');

%graph both functions once on two subplots
subplot(2,1,1);
plot(t,y1), grid on, legend('1.25*exp(-t)');    %plot y1 versus t
Limit=[0 16 -1 1];  %Initialize the limit
axis(Limit);        %set the limit for the function  
title('Problem #2 Part B');

subplot(2,1,2)
plot(t,y2,'y'),grid on, legend('2.02*exp(-0.3*t)'); %plot y2 versus t with yellow color
Limit=[0 16 -1 1];  %Initialize the limit
axis(Limit);        %set the limit for the function
********************************************************************************************

% Problem #3
x=[-5:0.1:5];       % Colon notation: starting value: increment: ending value 
y=x./(0.25+(x.^2)); %each element of x is divided by the corresponding element of (0.25+(x.^2))
                    %(x.^2) is the operation by 'x' apply to element of 2
plot(x,y), legend('this is an odd function'); grid on;  %plot y versus x
title('Problem #3');

*********************************************************************************************
% Problem #4
x1=[-0.5:0.01:1];   % Colon notation: starting value: increment: ending value 
y1=sin(pi.*x1);

x2=[1:0.01:3];      % Colon notation: starting value: increment: ending value 
y2=x2-1;

x3=[3:0.01:5];      % Colon notation: starting value: increment: ending value 
y3=(-2.*x3)+8;

plot(x1,y1,'.',x2,y2,'--',x3,y3), grid on; %plot y1 verus x1, y2 versus x2, y3 versus x3
legend ('sin(pi*x)', 'x-1', '-2x+8');
title('Problem # 4');
********************************************************************************************

%Problem #5
x=[-4:0.1:4];      % Colon notation: starting value: increment: ending value 
x1=exp(-x.^2);
x2=((x-1).^2)-2;
plot(x,x1,x,x2), grid on, legend('exp(-x^2)','((x-1)^2)-2');   %plot x1 and x2 versus t
Limit=[-2 3 -4 4];   %Intitialize the limit
axis(Limit);        %set the limit for the funcion
title('Problem #5');

[xp,yp]=ginput(1)   %choosing the intersection of the plot
xp, yp              %Displaying the intersection values

xp =

   -0.6233


yp =

    0.6199


xp =

   -0.6233


yp =

    0.6199
    xp =

    2.4297


yp =

   -0.0117


xp =

    2.4297


yp =

   -0.0117
