HW7soln - PETE2060ComputinginPetroleumEngineering...

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

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

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

View Full DocumentRight Arrow Icon
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);
Background image of page 2
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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

HW7soln - PETE2060ComputinginPetroleumEngineering...

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

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