Matlab Tutorials | Examples
Plotting: Concentrations, curve fitting, 3D Gaussian plot
Create the three plot windows detailed below using the data in the file practice12data.mat.
Your plots should match the provided sample outputs. Pay attention to titles, x-y labels, grids, legends and their positions, colours etc. Running your main script should produce all three plots, in separate windows. You can start new figure windows by giving the commanding figure.
In the structure array named reaction, you can find the time and concentration measurements for the chemical reaction
Create the two plots shown below within a figure window.
The plot at the top should show the molecule concentration of the three components of the reaction versus time.
The plot at the bottom should show the reaction rate versus time, where this rate is calculated using:
In the structure array named icecream, temperature and total ice-cream sales for arbitrary days are saved.
Plot sales versus temperature, using dots with marker size of 20.
Then find the first order polynomial that best fits this data and plot it on top of the previous plot. Using the coefficients of this polynomial, come up with an approximate equation between temperature and sales, and use this equation as the title of the plot. In the title, you can round values to the nearest integers.
Write a function named gaussian2d that gets four variables from its caller in its parameter list:
- Matrix containing the x-values of the grid
- Matrix containing the y-values of the grid
- The mean vector μ containing [μx, μy]
- The standard deviation vector σ containing [σx, σy]
The function should evaluate the below 2-dimensional Gaussian distribution function for the given x and y grid matrices. The result will be a matrix containing the z-values. This matrix must be returned to the caller program.
In your main program, create the 50×50 X and Y grid matrices in the interval [-1,1]. Call your gaussian2d function twice to get two surface matrices Z1 and Z2. The parameters for Z1 and Z2 (other than the X and Y grid matrices) are as follows:
In the third figure window, plot the surface Z = Z1 + Z2. Use colormap jet and view it from azimuth 45° and elevation 70°.
%%First Plot of First Figure
title('2NO_2 -> 2NO + O_2');
%%Calculate Rate for Second Plot
%Create second plot under of firstplot
%%%Open New Figure
title(['Sales ~ ' num2str(round(p(1))) ' x Temperature ' num2str(round(p(2)))]);
%%%Title can chage if polyfit changes
z1meanvector = [-0.2,0];
z2meanvector = [0.2,0];
std = [0.15,0.3];
[X,Y] = meshgrid(a,a);
Z=gaussian2d(X,Y,z1meanvector,std) + gaussian2d(X,Y,z2meanvector,std); %%Call function 2 times and add them
view(45,70); %%View angle
title('Sum of two Gaussian distributions');