Attribution Non-Commercial (BY-NC)

10 views

Attribution Non-Commercial (BY-NC)

- Scilab - Bag of tricks
- Visual Basic 6.0 Notes short
- COB and MULTI Threaded Rtns
- Spreadsheet-Based
- Art of Programming
- Chapter 2 Assembler
- IBM Datastage Interview Questions
- mnj
- Computer Applications in Civil Engineering Home Page
- Learning Slides
- HowScienceWorks--Graphs
- Lab 2
- Guidelines CS
- Td Win32asm 030.Asm
- Fortran Quick Reference Cheat Crib Sheet
- fdm_api
- cig-ap129_-en-p.pdf
- A Matlab Tutorial
- Advanced_BASIC_and_Machine_Code_for_the_Commodore_64.pdf
- 1

You are on page 1of 6

1) Log into your computer and open MatLab 2) If you dont have the previous M-scripts saved, you can find them at http://www.physics.arizona.edu/~physreu/dox/matlab_lesson_1.pdf, and http://www.physics.arizona.edu/~physreu/dox/matlab_lesson_2.pdf. More 3-D Graphing: isosurface Sometimes you have a scalar three-dimensional function. That is for every point in space (x,y,z) you have a value at that point, f(x,y,z). There is no complete way to graph this in 3-D since there are four variables: x, y, z, and f. However, if f is a continuous function, then you can restrict the graph to plot only where the values are equal. Copy the following script into a new M-file.

close all; clear all; clc; format long e; fun_function = inline('cos(x)+cos(y)+cos(z)','x','y','z'); % Don't really need to use an inline function here, % but just to review. points=linspace(-pi,pi,51); [x,y,z]=meshgrid(points,points,points); % Make a 3-D mesh grid or else graphing f won't work. % Notice this is a grid of 51^3 = 132,651 spatial points. f = fun_function(x,y,z); % Make the 132,651 data points at each spatial point. isosurface(x,y,z,f,1.1); grid on; title(['My Fun Function, Contour Value = ',num2str(1.1)]); xlabel('X');ylabel('Y');zlabel('Z'); axis([-pi,pi,-pi,pi,-pi,pi]);

Practice: Try this plot for contour values of 2, 1, .5, and .1.

Multiple Graphs Separate Figures You will often want to create more than one graph inside a program. Copy the following script into a new M-file.

close all; clear all; clc; format long e; x = linspace(0,10,100); y = linspace(-pi,pi,100); z = linspace(0,5,100); [X,Y,Z] = meshgrid(x,y,z); f_a = x.^3 - 2*x; f_b = (sin(X).^2).*cos(Y).*exp(-Z.^2); figure(1); % Make the first graph. isosurface(x,y,z,f_b,.2); figure(2); plot(x,f_a); % Make the second graph.

Practice: A particle is set to move in in the x-y plane via the parameterization: x=cos(2t) and y=sin(4t) for t = [0,5]. Create three graphs using one program that show x vs. t, y vs. t, and x vs. y.

Multiple Graphs Separate Figures (More) (SKIP THIS SECTION, GO TO NEXT PAGE.) Sometimes you have a scalar three-dimensional function. That is for every point in space (x,y,z) you have a value at that point, f(x,y,z). There is no complete way to graph this in 3-D since there are four variables: x, y, z, and f. However, if f is a continuous function, then you can restrict the graph to plot only where the values are equal. Copy the following script into a new M-file. close all; clear all; clc; format long e; fun_function = inline('cos(x)+cos(y)+cos(z)','x','y','z'); points=linspace(-pi,pi,51); [x,y,z]=meshgrid(points,points,points); f = fun_function(x,y,z); % Here is a trick for making multiple graphs. contour_values = [.1,.5,1,1.1,2]; for i_loop = 1:size(contour_values,2), figure(i_loop); isosurface(x,y,z,f,contour_values(i_loop)); grid on; title(['My Fun Function, Contour Value = ',... num2str(contour_values(i_loop))]) xlabel('X');ylabel('Y');zlabel('Z'); axis([-pi,pi,-pi,pi,-pi,pi]); end; Practice: No practice , but note how cool it is to automatically generate graphs.

Multiple Graphs Subplots (SKIP THIS SECTION FOR NOW, GO TO NEXT PAGE.) It is sometimes useful to make several graphs in the same figure, usually for easy comparison. This is done using subplot. Copy the following script into a new M-file.

close all; clear all; clc; format long e; x = linspace(0,10,100); figure(1); subplot(3,1,1); % '3' means set up 3 graphs verticaly, % '1' means 1 graph wide, and the last % '1' means the first plot. plot(x,cos(x)); title('Examine sin(x) times cos(x)'); subplot(3,1,2); % '2' for the second graph. plot(x,sin(x)); subplot(3,1,3); plot(x,sin(x).*cos(x));

Practice: Make three subplots horizontally arranged of a cycloid. Go to wikipedia, http://en.wikipedia.org/wiki/Cycloid, and find the correct parameterization of the cycloid.

Running Another M-file You may find that both your data analysis and graphing code getting very large. You can always separate them into two different programs and have one program run the other. 1) Copy the following script into a new M-file called one.m user_response = ... input('Are you happy? (''1'' for yes, ''2'' for no.) \n'); if user_response==1, disp('Oh brother!'); elseif user_response==2, disp('Boo hoo.'); else, disp('Wrong answer!'); end; 2) Now copy the following script into a new M-file called. close all; clear all; clc; format long e; user_response = input('Should I run one.m? (Y/n) \n','s'); if user_response=='Y', run one; % Notice that you don't type '.m' to run one.m. else, pause(); % 'pause()' waits for the user to type any key. fprintf('\n Whatever.\n\n'); pause(2); % 'pause(2)' waits for 2 seconds. fprintf('\n Goodbye.\n\n'); end; Practice: Make the above program also run another of your old M-files.

M-file Functions (SKIP THIS SECTION FOR NOW, GO TO NEXT PAGE.) The use of subroutine functions is common to all modern programming languages. Below is the simplest such example. There is a M-file-function called matt that takes two arrays and concatenates them together. The second M-file merely needs to use matt by giving it two input arrays. 1) Copy the following script into a new M-file called matt.m function m = matt(x_in, y_in) % Note that this function-line statement has % precise syntax you must follow. 'matt' here % must match the name of the M-file, 'matt.m', % and 'm' must be calculated below. m = [x_in,y_in]; % This statement determines the return value of the % function, 'm'. However, you can return more than % one variable by using '[m_1, m_2] = matt(x_in, y_in)' % as your function-line statement. 2) Now copy the following script into a new M-file called. close all; clear all; clc; format long e; x = [1,2,3]; y = [4,5]; matt(x,y)

Practice: Make an M-file function using your name that is cooler than mine.

(END OF LESSON 3)

- Scilab - Bag of tricksUploaded byvladadj_1603
- Visual Basic 6.0 Notes shortUploaded byjoinst1402
- COB and MULTI Threaded RtnsUploaded byAnonymous LJcUspq
- Spreadsheet-BasedUploaded bysumeja
- Art of ProgrammingUploaded byehsanrana
- Chapter 2 AssemblerUploaded bytabassum
- IBM Datastage Interview QuestionsUploaded byManoj Goyal
- mnjUploaded bySai_Kumar_1777
- Computer Applications in Civil Engineering Home PageUploaded bySanthosh Kumar Baswa
- Learning SlidesUploaded byJigneshShah
- HowScienceWorks--GraphsUploaded byJatin Mistry
- Lab 2Uploaded byVenkatrao Potluri
- Guidelines CSUploaded bychanderp_15
- Td Win32asm 030.AsmUploaded byz4rm4r
- Fortran Quick Reference Cheat Crib SheetUploaded byRaiWolf FA
- fdm_apiUploaded byrebecca4sem
- cig-ap129_-en-p.pdfUploaded byhzq1e
- A Matlab TutorialUploaded bynendya
- Advanced_BASIC_and_Machine_Code_for_the_Commodore_64.pdfUploaded byBruno Díaz
- 1Uploaded byArthurVilcaZevallos
- Lab-06_ 05_April2017Uploaded byraja
- Matlab commands and functionsUploaded byImran Parvez
- introduction to c++.pptxUploaded byIamIN
- A Systematic Approach to Hybrid Railway Power Conditioner Design With Harmonic Compensation for High-Speed RailwayUploaded byTechnico Technocrats
- 2018 Lab 5A Positive Feedback and Operational AmplifiersUploaded byPatrick Sibanda
- SophosUploaded bySREENI
- v64 Fil CD ManualUploaded byAhmed Kamal
- STM 3rd UnitUploaded byLakshmanrao Nayini
- Lecture 37 - Conceptual Aside by Value vs by ReferenceUploaded byTim Pron
- Course Outline Tp WindowsUploaded byAnonymous PcPkRpAKD5

- MATLAB_1Uploaded byMinhaj Akbar
- Statistics Made Easy-BasicsUploaded byFaylasoof
- Dynamic SimulationUploaded byFelipeGonzales
- Matlab for PsychologistsUploaded byAvinash Nandakumar
- MATLAB Course - Part 1Uploaded bykarincayazilim
- CSE catalogue.pdfUploaded byssn
- EEE3001 Software ManualUploaded byManuDubey
- Practise ProbelmsUploaded byahscen
- MATLAB LECTURE.pdfUploaded byAshish Gupta
- Getting Started With MATLAB - David HartUploaded byapi-3696482
- PETSc ManualUploaded byshainath
- Enhancing Control Engineering EducationUploaded bybmmostefa
- Mathematical modelUploaded bySubhadeep Chanda
- psat-2.0.0-b2Uploaded byYichi Zhang
- Power Systems Analytical Software ToolsUploaded bydskymaximus
- dsp_blksUploaded byLunokhod Rover
- Features - Database Toolbox - MATLABUploaded byalexverde3
- Intro-Matlab Matematica UnixUploaded byKalambilYunus
- PETSc Users Manual - Revision 3.7Uploaded byQueremosabarrabás A Barrabás
- ENGR112 HW2Uploaded byRenan Santos
- fuzzy_tbUploaded byJu-Suk Yang
- Integrating MATLAB with Verification of Image and Video.pdfUploaded bylauerami
- Johns Tutorial on Everyday MathcadUploaded bynnlice
- Generating Matlab CodeUploaded byLakshmi Anusha Munupalle
- MATLAB Support Package for Arduino (Aka ArduinoIO Package) - File Exchange - MATLAB CentralUploaded byclaytoncage
- GMT Manpages SupplUploaded byErdiApatay
- Introduction to Matlab MitUploaded byHalil İbrahim Küplü
- Matlab 1Uploaded byIchwan Setiawan
- Matlab Training - SIMULINKUploaded byAtta Rehman
- 01440979Uploaded byVenkata Krishna Chidaraboina

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.