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

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

View Full Document Right Arrow Icon
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:
Background image of page 1
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

This note was uploaded on 02/14/2010 for the course ASE 201 taught by Professor Hayes during the Spring '07 term at University of Texas.

Ask a homework question - tutors are online