Our zeros xarray 20510 161 guesses seems sufficient

• 16
• 100% (12) 12 out of 12 people found this document helpful

This preview shows page 6 - 9 out of 16 pages.

%our zeros xArray = 2:.05:10; %161 guesses seems sufficient enough %our array that has zeros the length of our x array which has our values %where F1 and F2 meet zerosArray = zeros(1, length(xArray)); %our array element thats a positive integer as to fill our zerosArray k = 1; %for loop which iterates through our x array to find our intersection %points for i = 1:length(xArray)-1; %This fzero function finds where our F3 function is equal to 0 with %respect to our x array at element i zeroF3 = fzero(F3, xArray(i)); %determines if one of our values is repeated, abs returns the value of %F3 rePeat = abs((zerosArray-zeroF3)) < 0.00006; %if loop that determines if a value is repeated or not by finding if %the sum of rePeat doesn't equal 0 if sum(rePeat) ~= 0; %nothing happens and the loop continues %iterates through our for loop else %our array input uses zeroF3 values that are unrepeated zerosArray(k) = zeroF3; %k is looped and is off to the next array value k = k + 1; %if loop that determines if a value is repeated or not by finding if %the sum of rePeat doesn't equal 0 end ; end ; %sets our zeros array value to not display intersection points below two %and after 10
Week 5 Homework ENGR 112 Fzero while zerosArray = zerosArray(zerosArray > 0); zerosArray = zerosArray(zerosArray < 10); %plots our Exp function fplot(F1, [0, 10]); %waits to plot hold on ; %plots our sin function fplot(F2, [0, 14]); %labels horizontal axis xlabel( 'x' ); %labels vertical axis ylabel( 'F(x)' ); %key for graph functions legend( 'F1: Exp' , 'F2:sin' ); %titles graph title( 'Intersection of Two Functions' ); %plots our zeros array function and marks our intersection points with an x plot(zerosArray, F1(zerosArray), 'X' ); %holds off, plots all hold off ; %prints our first and last root values fprintf( 'The first root is at %0.03f, last is at %0.03f, respectively.\n' , zerosArray(1), zerosArray(end-1)); Function Files % Copy and paste your functions here ( if any were used ). Must be size 10, same as MATLAB font and color. Command Window Output The first root is at 4.179, last is at 9.538, respectively. Answers to question(s) asked in the homework (if any) Extra credit responses: a) Because we are determine if a value is repeating rather than seeing if our value is equal to 0, and that small number keeps us within a range rather than checking to see if its equal to something b)
Week 5 Homework ENGR 112 Fzero while Problem 3 Epidemic Problem 5 Comments for grader/additional information (if any) Script File %Nick Vrvilo %Desc: This script models the evolution of an epidemic in a fixed population %through different time jumps. It divides the population into three %classes: susceptibles (those who never had the illness and can catch it), %infectives (those who are infected and are contagious), and recovered %(those who already had the illness and are immune). We use time step, h, %to calculate how an epidemic changes over time, and in this case we are %doing 140 time jumps of h, or 7 days. We are also called two different %functions, DiseaseSimulate and DiseaseStep, as they have the values for %the steps and the simulation values clear; %clears workspace %Below is notes help %How S(susceptibles) changes: dS/dt=-aSI/N
• • • 