HW7soln

# HW7soln - Problem1.Use a while loop to find the maximum...

This preview shows pages 1–4. Sign up to view the full content.

PETE 2060 – Computing in Petroleum Engineering Solution for homework 7 Problem 1. Use a while loop to find the maximum number in the following number and display the order of this number in the vector: x = [1, 23, 43, 72, 87, 56, 98, 33, 22, 109, 11] Solution. x=[1,23,43,72,87,56,98,33,22,109,11]; n=length(x); max=x(1); order=1; j=2; while j<(n+1) if max>x(j) max=max; else max=x(j); order=j; end end fprintf(‘\n The maximum number is %i, which is the %i –th element of vector x \n’, max, order)

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

View Full Document
Problem 2. Determine the real roots of 3 . 2 7 6 4 ) ( 2 3 + = x x x x f : Part a) x=0:0.01:1; f=4*x.^3 6*x.^2+7*x 2.3; plot(x,f); Second attempt x=0.20:0.01:0.6; f=4*x.^3 6*x.^2+7*x 2.3; plot(x,f); Third attempt x=0.40:0.01:0.5; f=4*x.^3 6*x.^2+7*x 2.3; plot(x,f);
Fourth attempt x=0.44:0.001:0.46; f=4*x.^3 6*x.^2+7*x 2.3; plot(x,f) After the fourth attempt, it seems that the root is somewhere between 0.450 and 0.451.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

HW7soln - Problem1.Use a while loop to find the maximum...

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

View Full Document
Ask a homework question - tutors are online