MATLAB LABORATORY SESSION SEE1012: Introduction to Electrical Engineering MATLAB LABORATORY SESSION
HELP To access MATLAB help or documentation >> help Or To access help on specific topic e.g. sin(x) >> help sin >> doc sin
PLOT MATLAB provides a number of plots Getting help on plot >> doc plot >> doc subplot >> doc plot3 >> doc pie >> doc polar >> doc bar After the CANCER project, the next innovation was the SPICE program. SPICE stands for Simulation Program with Integrated Circuit Emphasis. This new acronym was created from the fact that many of the components being placed on the new integrated circuit were becoming smaller than the discrete components themselves. With this in mind, the SPICE creators wanted to save money by not having to manufacture chips to test the circuits. The next logical step was to let a computer do the testing for them. By not building the physical circuit, the designers can save a lot of time and money.
PLOT MATLAB provides a number of plots Single plot e.g. >> x=0:pi/50:4*pi >> plot(x,sin(x)) After the CANCER project, the next innovation was the SPICE program. SPICE stands for Simulation Program with Integrated Circuit Emphasis. This new acronym was created from the fact that many of the components being placed on the new integrated circuit were becoming smaller than the discrete components themselves. With this in mind, the SPICE creators wanted to save money by not having to manufacture chips to test the circuits. The next logical step was to let a computer do the testing for them. By not building the physical circuit, the designers can save a lot of time and money.
PLOT Double line on single graph e.g. >> x=0:pi/50:4*pi >> plot(x,sin(x),x,cos(x)) After the CANCER project, the next innovation was the SPICE program. SPICE stands for Simulation Program with Integrated Circuit Emphasis. This new acronym was created from the fact that many of the components being placed on the new integrated circuit were becoming smaller than the discrete components themselves. With this in mind, the SPICE creators wanted to save money by not having to manufacture chips to test the circuits. The next logical step was to let a computer do the testing for them. By not building the physical circuit, the designers can save a lot of time and money.
PLOT Multiple separate graphs e.g. >> x=0:pi/50:4*pi >> subplot(1,2,1) >> plot(x,sin(x)) >> subplot(1,2,2) >> plot(x,cos(x)) After the CANCER project, the next innovation was the SPICE program. SPICE stands for Simulation Program with Integrated Circuit Emphasis. This new acronym was created from the fact that many of the components being placed on the new integrated circuit were becoming smaller than the discrete components themselves. With this in mind, the SPICE creators wanted to save money by not having to manufacture chips to test the circuits. The next logical step was to let a computer do the testing for them. By not building the physical circuit, the designers can save a lot of time and money.
PLOT 3 dimensional plot e.g. plot of a helix >> t = 0:pi/50:10*pi; >> plot3(sin(t),cos(t),t) >> grid on axis square After the CANCER project, the next innovation was the SPICE program. SPICE stands for Simulation Program with Integrated Circuit Emphasis. This new acronym was created from the fact that many of the components being placed on the new integrated circuit were becoming smaller than the discrete components themselves. With this in mind, the SPICE creators wanted to save money by not having to manufacture chips to test the circuits. The next logical step was to let a computer do the testing for them. By not building the physical circuit, the designers can save a lot of time and money.
PLOT MATLAB can draw a sphere >> sphere >> axis equal After the CANCER project, the next innovation was the SPICE program. SPICE stands for Simulation Program with Integrated Circuit Emphasis. This new acronym was created from the fact that many of the components being placed on the new integrated circuit were becoming smaller than the discrete components themselves. With this in mind, the SPICE creators wanted to save money by not having to manufacture chips to test the circuits. The next logical step was to let a computer do the testing for them. By not building the physical circuit, the designers can save a lot of time and money.
PLOT MATLAB can draw other shapes as well. >> [x,y] = meshgrid(-16:1.0:16); >> z = sqrt(x.^2 + y.^2 + 5000); >> surf(z) >> shading interp After the CANCER project, the next innovation was the SPICE program. SPICE stands for Simulation Program with Integrated Circuit Emphasis. This new acronym was created from the fact that many of the components being placed on the new integrated circuit were becoming smaller than the discrete components themselves. With this in mind, the SPICE creators wanted to save money by not having to manufacture chips to test the circuits. The next logical step was to let a computer do the testing for them. By not building the physical circuit, the designers can save a lot of time and money.
Solving Equations MATLAB provides many ways of solving equations Example Lets try solving two equations y=x2 and y=x+4 Get help on ‘solve’ >> doc solve
Solving Equations To solve the two equations >> S = solve('y-x^2','y-x-4’)
Solving Equations To solve the two equations >> s = solve('y-x^2','y-x-4’) This will flag an error. Why? >> s = solve('y-x.^2','y-x-4’) >> s.x >> x=double(s.x) >> y=double(s.y)
Solving Equations Lets see the intersection of the two graphs >> x=-2:.1:3 >> plot(x,x.^2,x,x+4)
Differentiation MATLAB is able to differentiate an equation Let y=x4+2x3+3x2+4x+5 >> y=[1 2 3 4 5] >> diff(y)
FUNCTION Function can be created using m-files. The name of the file must be similar to the name of the function. Create a new file Save the file as not_a_function.m in MATLAB subdirectory
Content of not_a_function Content of not_a_function.m file subplot(2,2,1) plot(x,sin(x)) subplot(2,2,2) plot(x,sin(x+pi/2)) subplot(2,2,3) plot(x,cos(x)) subplot(2,2,4) plot(x,cos(x+pi/2))
FUNCTION From the MATLAB workspace type : >> x=0:pi/50:4*pi; >> not_a_function
FUNCTION A function can be created by naming a file similar to the name of the function. Example To create a function, open not_a_function.m Save the file as myfunction.m in MATLAB subdirectory
Content of myfunction.m file function myfunction(x) % This is my first function in MATLAB % I hope I will use it a lot later % % See you then subplot(2,2,1) … plot(x,cos(x+pi/2))
FUNCTION From the MATLAB workspace type : >> clear x >> x=0:pi/50:4*pi; >> myfunction(x)
Symbolic Toolbox To use symbolic toolbox, type >> help syms To declare s as a variable >> syms s
Symbolic Toolbox To differentiate a function in s >> d=diff(3*s^2+4*s+5) To integrate a function in s >> i=int(d)
THE END