1 / 7

Matlab course – exercise # 1 Last day for submission: One week after HW was assigned

Matlab course – exercise # 1 Last day for submission: One week after HW was assigned Student Names and IDs: Omer Ramote (######) and Shahar Kidron (#####) Question 1. (Creating a working environment)

eliora
Télécharger la présentation

Matlab course – exercise # 1 Last day for submission: One week after HW was assigned

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Matlab course – exercise # 1 • Last day for submission: One week after HW was assigned • Student Names and IDs: Omer Ramote (######) and ShaharKidron (#####) • Question 1. (Creating a working environment) • For each hw you do in the course it is a good idea to open a new directory where you will keep that HW's programs and scripts. • Create a directory in Windows called C:\matlab_course\HW1. • Note we used C:\Documents and Settings\Administrator\My Documents\matlab_course\HW1 since this path is backed-up on our system. • In order for Matlab to recognize the programs in this directory please include it in the Matlab path (Reminder: go to FileSet Path  Add Folder). • Create a script called showDir that displays on the screen the current directory name. Save the script in the directory C:\matlab_course\HW1. • Run the script from the command line and check that it works properly. • >> showDir • C:\Documents and Settings\Administrator\My Documents\MATLAB • Change the current directory to C:\matlab_course\HW1 (using the cd in the command line) • Run showDir again • >> cd ('C:\Documents and Settings\Administrator\My Documents\matlab_course\HW1'); • >> showDir • C:\Documents and Settings\Administrator\My Documents\matlab_course\HW1 • From now on please save all the rest of the scripts in this HW in the directory C:\matlab_course\HW1.

  2. Question 2. • Create a script file called myName.m that prints your name (last and first) on the screen • >> myName • Ramote Omer and KidronShahar • Copy the previous script to a new script called myNameNew. • Use the Matlab help to learn about the function pause. • Include printing of your thesis title on the screen in the new version of the script (if you don't have any title just invent). Use pause between the printing of your name and the printing of your thesis title. • Run the script from the command line and check that it works properly. • >> myNameNew • Ramote Omer and KidronShahar • Identifying Novel Antibiotics using Whole Genome Sequencing Biases • Question 3. • (see output for questions 3 and 4 below) • Create a new script called findDist • Create a variable velocity that has the value 10 (m/sec); • Create a variable time that has the value 5 (sec); • Calculate the value of the variable distance (distance = velocity *time) • Display all variables in the workspace using the function whos. • Save in the memory the variable velocity (using the function save). • Delete the variable velocity from the workspace using the function clear. • Display now all the variables in the workspace. • Load from the memory the variable velocity. • For a demonstration of the meaning of the operator = in Matlab, increase the velocity value by a factor of 2. Display it on the screen. • Calculate the value of sinus of 15 degree and display it. (Use help for definition of function sin.)

  3. Question 4. A. Read in the help about the functions tic and toc. Use these functions formeasuring the run time of the calculation of sin(150) B. measuring the run time of the saving of this calculation result in the memory using the function save. Compare this run time with the result of A. (From this question you can compare the time duration of the CPU operation versus the time duration of the operations with memory.) >> findDist Displaying all variables: Name Size Bytes Class Attributes distance 1x1 8 double time 1x1 8 double velocity 1x1 8 double Displaying all variables after clearing velocity: Name Size Bytes Class Attributes distance 1x1 8 double time 1x1 8 double workspace_file 1x16 32 char Displaying velocity after loading it and multiplying it by 2: 20 Benchmarking sin calculation: Elapsed time is 0.002945 seconds. sin(15deg) is: 0.2588 Benchmarking save operation: Elapsed time is 0.002338 seconds. In this case the two operations took roughly the same time. However, usually disk operations are more time-consuming then simple calcul

  4. Relevant m-files: 1) showDir.m % MATLAB Intro 2010 % Omer Ramote (#####) and ShaharKidron (#####) % HW1, Question 1 % This script displays the current directory. disp(pwd); % displays current directory.

  5. 2) findDist % MATLAB Intro 2010 % Omer Ramote (#####) and ShaharKidron (######) % HW1, Question 3 and 4 % This script does a distance calculation and demonstrates how to save and % load variables and how to benchmark MATALAB operations. velocity = 10; % units: m/sec time = 5; % units: sec distance = velocity * time; disp('Displaying all variables:'); whos; % displays all variables in the workspace workspace_file = 'q3.workspace.mat'; % workspace dump file save(workspace_file, 'velocity'); % saves the variable velocity to disk clear('velocity'); % deletes the variable velocity from the workspace disp('Displaying all variables after clearing velocity:'); whos; % displays all variables in the workspace. now velocity is absent load(workspace_file); % loads velocity from workspace dump file velocity = velocity * 2; disp('Displaying velocity after loading it and multiplying it by 2:'); disp(velocity); disp('Benchmarking sin calculation:'); tic; % starts stopwatch sin15deg = sind(15); % calculates sin(15 deg) toc; % stops stopwatch and displays elapsed time

  6. disp('sin(15deg) is:'); disp(sin15deg); % displays sin(15 deg) value disp('Benchmarking save operation:'); tic; % starts stopwatch save('q3.sin15.mat', 'sin15deg'); toc; % stops stopwatch and displays elapsed time

  7. 3) myName % MATLAB Intro 2010 Omer Ramote (####) and ShaharKidron (####) % HW1, Question 2 % This script displays our names. disp('Ramote Omer and KidronShahar'); % displays our names. 4) myNameNew % MATLAB Intro 2010 % Omer Ramote (#####) and ShaharKidron (#####) % HW1, Question 2 % This script displays our names, pauses, and prints Shahar's thesis title % (Omer doesn't have one yet). disp('Ramote Omer and KidronShahar'); % displays our names. pause;% pauses until user input. disp('Identifying Novel Antibiotics using Whole Genome Sequencing Biases');

More Related