Thread Subject: fastest way to write code

Subject: fastest way to write code

From: Pr B

Date: 21 Mar, 2010 02:59:04

Message: 1 of 2

i have the following code that computes the function y(x) = pi * exp(-x) in 10001 in the interval x ∈ [0,100]:

x = 0;
for k = 1:10001
y(k) = exp(-x)*pi;
x = x + 0.01;
end

can this be written in a vectorized fashion?

Subject: fastest way to write code

From: Ziwen

Date: 21 Mar, 2010 03:25:05

Message: 2 of 2

x=0:0.01:100;
y=exp(-x)*pi;

"Pr B" <pb2297@columbia.edu> wrote in message <ho421o$4sm$1@fred.mathworks.com>...
> i have the following code that computes the function y(x) = pi * exp(-x) in 10001 in the interval x ∈ [0,100]:
>
> x = 0;
> for k = 1:10001
> y(k) = exp(-x)*pi;
> x = x + 0.01;
> end
>
> can this be written in a vectorized fashion?

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com