Lab 5: MATLAB Plotting and Function Building

 

 

MATLAB FILE

Lab 5: MATLAB Plotting and Function Building

Introduction: 

The following lab deals with MATLAB plotting and creating functions. Matlab plotting is an effective tool as it allows the user to visualize numerical data into visual data which may help in understanding and appreciating the effectiveness of why certain expressions are performed. Function building is important as it makes creating outputs from inputs easier, especially with MATLAB which can perform such function calculations in seconds. Function building enables users to create custom, reusable code tailored to specific needs, enhancing computational efficiency and accuracy. Together, they empower professionals to effectively analyze and interpret data, aiding in informed decision-making.

Procedures: 

 1. Write a MATLAB Function 


 Figure 1: MATLAB code in u.m 

1.1.) The two lines in the command window define a equation for a unit step function and plot it, respectively.    

1.2) When changing the step size of t from 0.001 to 0.1, the plot shifts to the left and is slightly off from where it once was on the x-axis as this is defined to be t or time. 

1.3) The expression y=t>=to directs MATLAB to create a unit ramp function beginning at time t0. Prior to t0, the function's value remains at 0, after, the value progresses linearly with t.


2. Ramp Function

 

Figure 2:MATLAB code in r.m

1.1)     Similarly, to the previous function build, y = (t-to).*(t>=to) is telling Matlab to generate a unit ramp which remains at zero until time t0 and then ascends linearly starting from t0.

  

Figure 3: 1st ramp function with defined variables 

Figure 4: 2nd ramp function with defined variables 

3.  Plotting Skills 

Figure 5: Unit step function and ramp function on single figure, utilizing subplots. 

4. Build the Pulse Function   

Figure 6: Pulse function, tau=1.

 

Figure 7: Pulse function, tau=4. 

5. Generate a Script with Different Sections  

5.1) subplot allows multiple plots within a single figure window, ideal for side-by-side comparisons. In contrast, figure opens a new window for each plot, providing an isolated view. While subplot is great for closely related data, figure is suitable for independent plots or when separation is desired. 

Figure 8: Plots of step, ramp, and pulse functions all in one graph.

Figure 9: x1(t) and x2(t) plots.

Conclusions: 

The freedom the experiment granted was thoroughly enjoyed. The opportunity to use MATLAB help and independent research allowed for freedom of learning new techniques and appreciation for plotting and function building. Plotting in MATLAB provides visual insight into data, revealing trends and patterns. Function building fosters modularity and efficiency, streamlining repetitive tasks and enabling organized, reusable code structures. Together, they enhance MATLAB's utility in data analysis and research.

 

Comments

Popular Posts