daniel
daniel

Reputation: 966

What am I doing wrong in Matlab?

I have this problem (first picture) that gets a wrong plot in the red dashed line in the second picture, while it should get the plot with the solid blue line, which is in the third picture, which I got from Chegg.com.

I figured out with some help that 18.7*exp(-0.0193*t) diminishes to nearly 0. Therefore the divisor (1+18.7*exp(-0.0193*t)) will always be practically a value of 1, and P will always be practically 11.5.

Here is my script:

x1 = [1850, 1910, 1950, 1980, 2000, 2010];
y1 = [1.3, 1.75, 3, 4.4, 6, 6.8];
x2 = [1900:10:2200];
P = 11.55./(1+18.7*exp(-0.0193*x2))
plot(x1, y1, 'g*', x2, P, '--r')

Here's the results of the Command Window:

P =

Columns 1 through 11

11.5500 11.5500 11.5500 11.5500 11.5500 11.5500 11.5500 11.5500 11.5500 11.5500 11.5500

Columns 12 through 22

11.5500 11.5500 11.5500 11.5500 11.5500 11.5500 11.5500 11.5500 11.5500 11.5500 11.5500

Columns 23 through 31

11.5500 11.5500 11.5500 11.5500 11.5500 11.5500 11.5500 11.5500 11.5500

Problem:

enter image description here

My plot:

My plot results

Chegg plot:

Chegg plot

Upvotes: 0

Views: 40

Answers (1)

Cris Luengo
Cris Luengo

Reputation: 60504

The text says "t is in years since 1850". So I think you need to do:

P = 11.55./(1+18.7*exp(-0.0193* (x2-1850) )
                                 ^^^^^^^

You are plotting the tail of the function only, rather than the interesting part.

Upvotes: 2

Related Questions