REC12+Problems+Set+Solutions

REC12+Problems+Set+Solutions - 14:440:127 Introduction to...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
14:440:127 Introduction to Computers for Engineers Recitation 12 - Solutions 1. Plotting Over the past 5 years, the number of students in some Computer Vision class has been 15, 25, 55, 115, 144. Class size seems like it ʼ s growing exponentially. To verify this, plot these values on a plot with a log y scale and label it ( semilogy, xlabel, ylabel, title ). Use magenta square symbols of marker size 10 and line width 4, and no line connecting them. (marker size and line width are both properties that you can change direction in a line of code - type in help plot to see examples.) You may have to change the x limits to see all 5 symbols ( xlim ). If the relationship really is exponential, it will look linear on a log plot. The script that generates the desired Fgure is pasted below: % plotClassSize % plots the number of students in 6.094 over 5 years on a semilog plot % open a figure and plot the data figure semilogy([1 2 3 4 5],[15 25 55 115 144],'ms','markersize', 10,'linewidth',4); % change x limits and label it xlim([0.5 5.5]); xlabel('Year'); ylabel('Number of Students') title('Number of students per year in 6.094'); 2.±unction Make function M-Fle called myLoopTest (N) that loops through the values 1 through N and for each number n it should display ʻ n is divisible by 2 ʼ , ʻ n is divisible by 3 ʼ , ʻ n is divisible by 2 AND 3 ʼ or ʻ n is NOT divisible by 2 or 3 ʼ . Use a for loop, the function mod or rem to Fgure out if a number is divisible by 2 or 3, and num2str to convert each number to a string for displaying. You can use any combination of if, else, and elseif. % myLoopTest(N) % % loops through the values 1 to N and for each number, displays whether the % number is divisible by 2, 3, both 2 and 3, or neither function myLoopTest(N) % loop through the numbers for n=1:N if ~rem(n,2) % if divisible by 2
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
if ~rem(n,3) % if also divisible by 3 disp([num2str(n) ' is divisible by 2 and 3']) else % divisible by 2 but not 3 disp([num2str(n) ' is divisible by 2']) end elseif ~rem(n,3) % if divisible by 3 but not 2 disp([num2str(n) ' is divisible by 3']); else % not divisible by either disp([num2str(n) ' is NOT divisible by 2 or 3']); end end 3.System of Equations Solve the following system of equations. Compute and display the error vector, which is A*(your Fndings) - b. 3a + 6b + 4c = 1 a + 5b = 2 7b + 7c = 3 % make the matrix and right hand side vector, then solve using \ mat=[3 6 4;1 5 0;0 7 7]; y=[1;2;3]; abc=mat\y; % check that the solution is correct, if it is, this should be % close to 0 errorVector=mat*abc-y 4.Fitting Line to Data Write a script to load the data Fle myRandData.mat (which contains variables x and y ) and Ft Frst, second, third, fourth, and Ffth degree polynomials to it. Plot the data as blue dots on a Fgure, and plot all Fve polynomial Fts using lines of different colors and increased widths. on the same axes. (line width is a property that you can change direction in a line of code - type in help plot to see examples.) Label the Fgure
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/24/2011 for the course ENGINEERIN 127 taught by Professor Finch during the Spring '08 term at Rutgers.

Page1 / 13

REC12+Problems+Set+Solutions - 14:440:127 Introduction to...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online