f



Matlab Problem, Need Help Urgent

Consider the integral
 ∫0   e-x sin(2x) dx
  ∏/4

a)	Use the trapezoidal rule, and Simpson’s rule to approximate the integral.
b)	Compute the exact error in each case of part (a), and compare the exact error to the error bound associated for each integration method used.
Hint: 
Use
function s=simprl(f,a,b,M)
 
%Input    - f is the integrand input as a string 'f'
%         - a and b are upper and lower limits of integration
%         - M is the number of subintervals
%Output   - s is the simpson rule sum
 
 
h=(b-a)/(2*M);
s1=0;
s2=0;
 
for k=1:M
   x=a+h*(2*k-1);
   s1=s1+feval(f,x);
end
for k=1:(M-1)
   x=a+h*2*k;
   s2=s2+feval(f,x);
end
 
s=h*(feval(f,a)+feval(f,b)+4*s1+2*s2)/3;
 

function s=traprl(f,a,b,M)
 
%Input    - f is the integrand input as a string 'f'
%         - a and b are upper and lower limits of integration
%         - M is the number of subintervals
%Output   - s is the trapezoidal rule sum
 
h=(b-a)/M;
s=0;
 
for k=1:(M-1)
   x=a+h*k;
   s=s+feval(f,x);
end
 
s=h*(feval(f,a)+feval(f,b))/2+h*s;
0
6/13/2007 12:16:27 PM
comp.soft-sys.matlab 211266 articles. 23 followers. lunamoonmoon (257) is leader. Post Follow

7 Replies
825 Views

Similar Articles

[PageSpeed] 39

On Jun 13, 9:16=C2=A0pm, Uncle Sam <samhobe...@gmail.com> wrote:
> Consider the integral
> =C2=A0=E2=88=AB0 =C2=A0 e-x sin(2x) dx
> =C2=A0 =E2=88=8F/4
>
> a) =C2=A0 =C2=A0 =C2=A0Use the trapezoidal rule, and Simpson=E2=80=99s ru=
le to approximate the integral.
> b) =C2=A0 =C2=A0 =C2=A0Compute the exact error in each case of part (a), =
and compare the exact error to the error bound associated for each integrat=
ion method used.
> Hint:
> Use
> function s=3Dsimprl(f,a,b,M)
>
> %Input =C2=A0 =C2=A0- f is the integrand input as a string 'f'
> % =C2=A0 =C2=A0 =C2=A0 =C2=A0 - a and b are upper and lower limits of int=
egration
> % =C2=A0 =C2=A0 =C2=A0 =C2=A0 - M is the number of subintervals
> %Output =C2=A0 - s is the simpson rule sum
>
> h=3D(b-a)/(2*M);
> s1=3D0;
> s2=3D0;
>
> for k=3D1:M
> =C2=A0 =C2=A0x=3Da+h*(2*k-1);
> =C2=A0 =C2=A0s1=3Ds1+feval(f,x);
> end
> for k=3D1:(M-1)
> =C2=A0 =C2=A0x=3Da+h*2*k;
> =C2=A0 =C2=A0s2=3Ds2+feval(f,x);
> end
>
> s=3Dh*(feval(f,a)+feval(f,b)+4*s1+2*s2)/3;
>
> function s=3Dtraprl(f,a,b,M)
>
> %Input =C2=A0 =C2=A0- f is the integrand input as a string 'f'
> % =C2=A0 =C2=A0 =C2=A0 =C2=A0 - a and b are upper and lower limits of int=
egration
> % =C2=A0 =C2=A0 =C2=A0 =C2=A0 - M is the number of subintervals
> %Output =C2=A0 - s is the trapezoidal rule sum
>
> h=3D(b-a)/M;
> s=3D0;
>
> for k=3D1:(M-1)
> =C2=A0 =C2=A0x=3Da+h*k;
> =C2=A0 =C2=A0s=3Ds+feval(f,x);
> end
>
> s=3Dh*(feval(f,a)+feval(f,b))/2+h*s;

So, your Professor has kindly supplied you with the functions you need
to solve your homework problem.
What's the problem?
Just bang the function in and solve it.
Easy peasy.
Wow, these students have it easy these days!!
In my day, we'd have had to solve it by hand using a slide rule or
abacus.


0
mulgor (3008)
6/13/2007 9:49:30 AM
In article <1181728170.481025.287880@g37g2000prf.googlegroups.com>, NZTideMan <mulgor@gmail.com> wrote:

> On Jun 13, 9:16 pm, Uncle Sam <samhobe...@gmail.com> wrote:
> > Consider the integral
> >  ∫0   e-x sin(2x) dx
> >   ∏/4
> >
> > a)      Use the trapezoidal rule, and Simpson’s rule to approximate the 
> > integral.

(snip)

> > s=h*(feval(f,a)+feval(f,b))/2+h*s;
> 
> So, your Professor has kindly supplied you with the functions you need
> to solve your homework problem.
> What's the problem?
> Just bang the function in and solve it.
> Easy peasy.
> Wow, these students have it easy these days!!
> In my day, we'd have had to solve it by hand using a slide rule or
> abacus.

They let you use a slide rule or abacus? Wow, you
had it easy.

We had to make our own abacus from pieces of stone
as remnants of rocks we broke apart ourselves. We
made slide rules from two sticks, putting marks on
them with our own blood. 

Then they took away our stickrules, so we scratched
lines in the dirt on both sides of the San Andreas
fault, and waited for an earthquake of just the
correct size and in the right direction.

But we loved every minute of it. ;-)

John


-- 
The best material model of a cat is another, or preferably the same, cat.
A. Rosenblueth, Philosophy of Science, 1945

Those who can't laugh at themselves leave the job to others.
Anonymous
0
woodchips (7944)
6/13/2007 10:50:00 AM
"John D'Errico" <woodchips@rochester.rr.com> wrote in message 
news:woodchips-061B6C.06500013062007@news.rochester.rr.com...
> In article <1181728170.481025.287880@g37g2000prf.googlegroups.com>, 
> NZTideMan <mulgor@gmail.com> wrote:
>
>> On Jun 13, 9:16� pm, Uncle Sam <samhobe...@gmail.com> wrote:
>> > Consider the integral
>> > � �^�0 � e-x sin(2x) dx
>> > � �^�/4
>> >
>> > a) � � � Use the trapezoidal rule, and Simpson�?Ts rule to approximate 
>> > the
>> > integral.
>
> (snip)
>
>> > s=h*(feval(f,a)+feval(f,b))/2+h*s;
>>
>> So, your Professor has kindly supplied you with the functions you need
>> to solve your homework problem.
>> What's the problem?
>> Just bang the function in and solve it.
>> Easy peasy.
>> Wow, these students have it easy these days!!
>> In my day, we'd have had to solve it by hand using a slide rule or
>> abacus.
>
> They let you use a slide rule or abacus? Wow, you
> had it easy.
>
> We had to make our own abacus from pieces of stone
> as remnants of rocks we broke apart ourselves. We
> made slide rules from two sticks, putting marks on
> them with our own blood.
>
> Then they took away our stickrules, so we scratched
> lines in the dirt on both sides of the San Andreas
> fault, and waited for an earthquake of just the
> correct size and in the right direction.
>
> But we loved every minute of it. ;-)
>
> John
>
>
> -- 
> The best material model of a cat is another, or preferably the same, cat.
> A. Rosenblueth, Philosophy of Science, 1945
>
> Those who can't laugh at themselves leave the job to others.
> Anonymous

Okay... to the logical conclusion...

  Michael Palin, Eric Idle, Graham Chapman and Terry Jones (in that order) 
are sitting around in bamboo chairs at a tropical resort, drinking wine, 
smoking cigars, and reminiscing about the good old days.

  Idle: Who would have thought, thirty years ago, we'd all be sitting here 
drinking Chateau de Chatterly, eh?

  Palin:  Them days, we'd be glad to have the price of a cup of tea.

  Chapman:  A cup of cold tea.

  Idle: Without milk or sugar.

  Jones:  Or tea.

  Palin:  In a cracked cup and all.

  Idle:  Oh, we never used to have a cup. We'd have to drink out of a rolled 
up newspaper.

  Chapman:  The best we could manage was to suck on a piece of damp cloth.

  Jones:  But you know, we were happy in those days, although we were poor.

  Palin:  Because we were poor. My old dad used to say to me, "Money doesn't 
bring you happiness, son".

  Idle:  He was right. I was happier then and I had nothing. We used to live 
in this tiny old tumbled down house with great big holes in the roof.

  Chapman:  House. You were lucky to live in a house. We used to live in one 
room, all twenty-six of us, no furniture, half the floor was missing, we 
were all huddled together in one corner for fear of falling.

  Jones:  You were lucky to have a room. We used to have to live in the 
corridor.

  Palin:  Oh, we used to dream of living in the corridor. It would have been 
a palace to us. We used to live on an old water tank in a rubbish dump. We 
used to wake up every morning by having a load of rotting fish dumped all 
over us. House, humph.

  Idle:  Well, when I say "house", it was just a hole in the ground covered 
by a sheet of tarpaulin. But it was a house to us.

  Chapman:  We were evicted from our hole in the ground. We had to go and 
live in a lake.

  Jones:  You were lucky to have a lake. There were a hundred and fifty of 
us living in a shoe box in the middle of the road.

  Palin:  Cardboard box?

  Jones:  Aye.

  Palin:  You were lucky. We lived for three months in a rolled up newspaper 
in a septic tank. We used to have to get up every morning at six o'clock and 
clean the newspaper, go to work down at the mill fourteen hours a day, week 
in, week out for sixpence a week and when we got home, our dad would thrash 
us to sleep with his belt.

  Chapman:  Luxury. We used to have to get out of the lake at three o'clock 
in the morning, clean the lake, eat a handful of hot gravel, work twenty 
hours a day at the mill for tuppence a month, come home and our dad would 
beat us around the head and neck with a broken bottle if we were lucky.

  Jones:  Well of course, we had it tough. We used to have to get out of the 
shoe box in the middle of the night and lick the road clean with our 
tongues. We had to eat half a handful of freezing cold gravel whilst working 
all day in that mill for fourpence every six years and when we got home our 
dad would slice us in two with a bread knife.

  Idle:  Right. I had to get up in the morning at ten o'clock at night, half 
an hour before I went to bed, eat a lump of cold poison, work twenty-nine 
hours a day down mill and pay the mill owner for permission to come to work 
and when we got home, our dad would kill us and dance about on our graves 
singing halleluja.

  Palin:  And you try and tell the young people of today that, and they 
won't believe you.

  Idle, Chapman and Jones:  No, no they won't.


0
6/13/2007 11:00:43 PM
On Jun 14, 11:00 am, "Ken Davis" <kendavis.nos...@alum.mit.edu> wrote:
> "John D'Errico" <woodch...@rochester.rr.com> wrote in message
>
> news:woodchips-061B6C.06500013062007@news.rochester.rr.com...
>
>
>
>
>
> > In article <1181728170.481025.287...@g37g2000prf.googlegroups.com>,
> > NZTideMan <mul...@gmail.com> wrote:
>
> >> On Jun 13, 9:16=C2 pm, Uncle Sam <samhobe...@gmail.com> wrote:
> >> > Consider the integral
> >> > =C2 =E2^=AB0 =C2 e-x sin(2x) dx
> >> > =C2 =E2^ /4
>
> >> > a) =C2 =C2 =C2 Use the trapezoidal rule, and Simpson=E2?Ts rule to a=
pproximate
> >> > the
> >> > integral.
>
> > (snip)
>
> >> > s=3Dh*(feval(f,a)+feval(f,b))/2+h*s;
>
> >> So, your Professor has kindly supplied you with the functions you need
> >> to solve your homework problem.
> >> What's the problem?
> >> Just bang the function in and solve it.
> >> Easy peasy.
> >> Wow, these students have it easy these days!!
> >> In my day, we'd have had to solve it by hand using a slide rule or
> >> abacus.
>
> > They let you use a slide rule or abacus? Wow, you
> > had it easy.
>
> > We had to make our own abacus from pieces of stone
> > as remnants of rocks we broke apart ourselves. We
> > made slide rules from two sticks, putting marks on
> > them with our own blood.
>
> > Then they took away our stickrules, so we scratched
> > lines in the dirt on both sides of the San Andreas
> > fault, and waited for an earthquake of just the
> > correct size and in the right direction.
>
> > But we loved every minute of it. ;-)
>
> > John
>
> > --
> > The best material model of a cat is another, or preferably the same, ca=
t=2E
> > A. Rosenblueth, Philosophy of Science, 1945
>
> > Those who can't laugh at themselves leave the job to others.
> > Anonymous
>
> Okay... to the logical conclusion...
>
>   Michael Palin, Eric Idle, Graham Chapman and Terry Jones (in that order)
> are sitting around in bamboo chairs at a tropical resort, drinking wine,
> smoking cigars, and reminiscing about the good old days.
>
>   Idle: Who would have thought, thirty years ago, we'd all be sitting here
> drinking Chateau de Chatterly, eh?
>
>   Palin:  Them days, we'd be glad to have the price of a cup of tea.
>
>   Chapman:  A cup of cold tea.
>
>   Idle: Without milk or sugar.
>
>   Jones:  Or tea.
>
>   Palin:  In a cracked cup and all.
>
>   Idle:  Oh, we never used to have a cup. We'd have to drink out of a rol=
led
> up newspaper.
>
>   Chapman:  The best we could manage was to suck on a piece of damp cloth.
>
>   Jones:  But you know, we were happy in those days, although we were poo=
r=2E
>
>   Palin:  Because we were poor. My old dad used to say to me, "Money does=
n't
> bring you happiness, son".
>
>   Idle:  He was right. I was happier then and I had nothing. We used to l=
ive
> in this tiny old tumbled down house with great big holes in the roof.
>
>   Chapman:  House. You were lucky to live in a house. We used to live in =
one
> room, all twenty-six of us, no furniture, half the floor was missing, we
> were all huddled together in one corner for fear of falling.
>
>   Jones:  You were lucky to have a room. We used to have to live in the
> corridor.
>
>   Palin:  Oh, we used to dream of living in the corridor. It would have b=
een
> a palace to us. We used to live on an old water tank in a rubbish dump. We
> used to wake up every morning by having a load of rotting fish dumped all
> over us. House, humph.
>
>   Idle:  Well, when I say "house", it was just a hole in the ground cover=
ed
> by a sheet of tarpaulin. But it was a house to us.
>
>   Chapman:  We were evicted from our hole in the ground. We had to go and
> live in a lake.
>
>   Jones:  You were lucky to have a lake. There were a hundred and fifty of
> us living in a shoe box in the middle of the road.
>
>   Palin:  Cardboard box?
>
>   Jones:  Aye.
>
>   Palin:  You were lucky. We lived for three months in a rolled up newspa=
per
> in a septic tank. We used to have to get up every morning at six o'clock =
and
> clean the newspaper, go to work down at the mill fourteen hours a day, we=
ek
> in, week out for sixpence a week and when we got home, our dad would thra=
sh
> us to sleep with his belt.
>
>   Chapman:  Luxury. We used to have to get out of the lake at three o'clo=
ck
> in the morning, clean the lake, eat a handful of hot gravel, work twenty
> hours a day at the mill for tuppence a month, come home and our dad would
> beat us around the head and neck with a broken bottle if we were lucky.
>
>   Jones:  Well of course, we had it tough. We used to have to get out of =
the
> shoe box in the middle of the night and lick the road clean with our
> tongues. We had to eat half a handful of freezing cold gravel whilst work=
ing
> all day in that mill for fourpence every six years and when we got home o=
ur
> dad would slice us in two with a bread knife.
>
>   Idle:  Right. I had to get up in the morning at ten o'clock at night, h=
alf
> an hour before I went to bed, eat a lump of cold poison, work twenty-nine
> hours a day down mill and pay the mill owner for permission to come to wo=
rk
> and when we got home, our dad would kill us and dance about on our graves
> singing halleluja.
>
>   Palin:  And you try and tell the young people of today that, and they
> won't believe you.
>
>   Idle, Chapman and Jones:  No, no they won't.- Hide quoted text -
>
> - Show quoted text -

Oh yes, that and the Dead Parrot skit were their best.

0
mulgor (3008)
6/14/2007 1:49:16 AM
On Jun 13, 5:49 pm, NZTideMan <mul...@gmail.com> wrote:
>
> Oh yes, that and the Dead Parrot skit were their best.

Come on you guys, he said this is URGENT. So stop messing around!

0
spasmous (238)
6/14/2007 4:33:50 AM
On Jun 14, 4:33 pm, spasmous <spasm...@gmail.com> wrote:

> Come on you guys, he said this is URGENT. So stop messing around!

Oh, I beg your pardon, but I did tell him what to do in my first
posting:
"Just bang the function in and solve it."
I thought that was a pretty clear instruction.

0
mulgor (3008)
6/14/2007 7:36:26 AM
spasmous <spasmous@gmail.com> wrote in
news:1181795630.235146.39080@z28g2000prd.googlegroups.com: 

> On Jun 13, 5:49 pm, NZTideMan <mul...@gmail.com> wrote:
>>
>> Oh yes, that and the Dead Parrot skit were their best.
> 
> Come on you guys, he said this is URGENT. So stop messing
> around! 
> 

with apologies to Python...

Man: Look, I CAME HERE FOR HELP, I'm not going to just stand...!!

Mr Barnard: OH, oh I'm sorry, but this is abuse.

Man: Oh, I see, well, that explains it.

Mr Barnard: Ah yes, you want room 12A, Just along the corridor.

[ http://orangecow.org/pythonet/sketches/argument.htm ]

Adrian



0
acherry (59)
6/14/2007 8:11:14 AM
Reply: