Quiz5_Solution

Quiz5_Solution - quiz5.m clear close all x_min =...

This preview shows page 1. Sign up to view the full content.

Quiz 5: Advanced While Loops Name: ASE 201 Write a MATLAB script (BE SURE TO USE MATLAB NOTATION!) that will plot the function y ( x ) = 7 x 3 + x 2 - 20 x + 11 from x min x x max with an increment of dx . Your script should complete the following tasks: 1. Read-in values for x min , x max and dx . 2. Build up the x and y arrays using a while loop. 3. Plot the function. 4. Include x -axis and y - axis labels and a title Note you are required to use a while loop. You are NOT allowed to use array arithmetic. Solution:
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % quiz5.m clear close all x_min = input(’Enter the minimum value for x: ’); x_max = input(’Enter the maximum value for x: ’); dx = input(’Enter the step size for x: ’); x = x_min; xp = x; % Could also start with empty arrays yp = 7*x^3+x^2-20*x+11; while x <= x_max x = x + dx; y = 7*x^3+x^2-20*x+11; xp = [xp,x]; yp = [yp,y]; end plot(xp,yp) xlabel(’x’) ylabel(’y(x)’) title(’Plot of 7x^3+x^2-20x+11’)...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online