I need to multiply all numbers from 1 to 500 together and all odd numbers from 1 to 1000.

I tried prod(1:500) and prod(1:2:999) and I was given Inf. Is there any way to have this give me an rational number? I also need to plot e^z where z goes from 1-1000 so I tried z=1:1000 e=exp(z) plot(z,e) It gives me the very similar problem of only getting rational numbers for very few entries because it automatically takes the answer to a magnitude of 307. Any help is appreciated.

2 Comments

Why do you need such huge numbers? What are you really trying to do? Give us the big picture here. Maybe there's another way to do it that doesn't involve overflowing.
It's an assignment for my engineering class. It said
1) What is the product of all numbers from 1 to 500 (1*2*3*4 etc)? How long did it take the computer to compute this? 2) What is the product of all odd numbers from 1 to 1000? 3) Compute the values for the function e^x for x = 0:1:1000 a. Put these values into a matrix b. Plot these values as e^x versus x

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

on 3 Nov 2015

Commented:

on 3 Nov 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!