Tuesday, March 10, 2015

Solved Example in Matlab (4-2nd Grade Class of Mechatronics Dept).

Example: Write Matlab Script that enables user to enter x start, end, and incrementing values necessary to plot the following two functions: Y = exp(x^2) , and Y = sin(x) using two separate figures with title for each graph and labels for x axis (values), and (Amplitude) for y axis? This procedure may continue according to user's control!
Solution:

%******************************************
%* Plotting 2 Function in 2 Figures!  *
%* Program Name: plot2figs             *
%******************************************

ch = 'y';
while (ch == 'y') || (ch == 'Y')
   
     clc, close all;
     xs = input ('Enter x   start value: ');
     xe = input ('Enter x   end   value: ');
     xc = input ('Enter increment value: ');
     X=(xs:xc:xe);
     Y=exp(X.^2);
     plot(X,Y)
     ylabel('Exp (X^2)')
     title('Function y = exp(x^2)')
     figure
     Y=sin(X);
     plot(X,Y,'r')
     ylabel('sin (X) in radian')
     title('Function y = sin (X)')
     disp('===========================');
     ch = input ('Try again (Y/N)? : ','s');
end

0 Comments:

Post a Comment

السلام عليكم...سارد بعد قرائتي للتعليق...شكرا

<< Home