Boy, am I really confused about this!!! I have an assignment that is wanting me to create a python statement that will produce f(x) for:
f(x) = 2xcubed - 8xsquared + x +16.

Then, using the same function, write a python program that will find the extrema (both high and low) for the function across the closed interval (-1,3).

HELP!!!

Recommended Answers

All 5 Replies

Well, the following should do the trick:

def func(x):
	y = (2*x*x*x) - (8*x*x) + x + 16
	return y

The best I can think of is a function that scans across the region of interest, maybe calculating f(x) for every 0.01 on the x axis. You can increase this resolution based on the accuracy you want.

The simplest way to get your x values in small increments is with a while loop. Then simply append (y, x) tuples to a list and use the min() and max() functions.

Thanks for replying. This stuff is so confusing to me. I've got some of the while loop, but not all of it.
highest = -9999999
x = -1.0
while x is < 3:
y = ?
if y >......... highest:
?
x = x + ?

The simplest way to get your x values in small increments is with a while loop. Then simply append (y, x) tuples to a list and use the min() and max() functions.

Thanks for replying. This stuff is so confusing to me. I've got some of the while loop, but not all of it.
highest = -9999999
x = -1.0
while x is < 3:
y = ?
if y >......... highest:
?
x = x + ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.