Homework 8, due November 13, 2008.

Due Thursday, November 13, 2008.
Post Reply
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Homework 8, due November 13, 2008.

Post by goodwine »

Please don't upload your programs by replying here. Do it in the uploads topic.

Reading: The material regarding functions in the chapter on subprograms.

Collaborative Problem: Write a FORTRAN program that:
  1. has a double precision function called "mysine" that uses your series approximation from before to compute the sine of an angle;
  2. an integer function called "fact" that computes the factorial and is used in the sine series by the sine function;
  3. prints out the output from your function and compares it with the built-in sin() function for angles of 0.1, 0.2 ... 1.0 (radians);
  4. has "implicit none" at the top.
If I did it correctly, when I wrote the program there was very little error if I carried the series out to 5 terms (through the 9th power).

Individual Problem: Modify your collaborative problem to try the following:
  1. have the mysine function call itself from inside and indicate what happens;
  2. have mysine call fact (which it should already do) and then have fact call mysine and indicate what happens;
  3. give the nonmodified mysine and integer argument and fact a double precision argument and indicate what happens;
  4. have a function have itself as its argument, e.g., mysine(mysine(.1)) and indicate what happens.
In all cases, by "indicate what happens" tell if pgf77 compiles it or not, whether it gives a warning, and if it can run whether it gives the right answer.
Bill Goodwine, 376 Fitzpatrick
bcastel1

Re: Homework 8, due November 13, 2008.

Post by bcastel1 »

Professor,

I am having trouble when it comes to transferring values for variables over from the main program to the functions, or vice versa. I print the variable in the function to see what it's final value is, the value that should be getting sent out, and then I print the value that the variable in the main program is assigned, and the two are way off. Any suggestions?

Brian Castello
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 8, due November 13, 2008.

Post by goodwine »

bcastel1 wrote:I am having trouble when it comes to transferring values for variables over from the main program to the functions, or vice versa. I print the variable in the function to see what it's final value is, the value that should be getting sent out, and then I print the value that the variable in the main program is assigned, and the two are way off. Any suggestions?
The two most common things to mess up are not to have the variable in the function as exactly the same name as the function. The other thing is to make sure everything is declared properly, both in the main program and the function. If those aren't it, then you will have to bring your code to me.
Bill Goodwine, 376 Fitzpatrick
eguilbea

Re: Homework 8, due November 13, 2008.

Post by eguilbea »

Professor,
What exactly do you want us to do when we compare our sine function to the built-in sine function. Do you want us just to print one right after the other to show that they are consistent, or do you want us to perform some kind of math operation?

Eddie Guilbeau
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 8, due November 13, 2008.

Post by goodwine »

eguilbea wrote:What exactly do you want us to do when we compare our sine function to the built-in sine function. Do you want us just to print one right after the other to show that they are consistent, or do you want us to perform some kind of math operation?
What I did was to compute the percentage error.
Bill Goodwine, 376 Fitzpatrick
Buchi

Re: Homework 8, due November 13, 2008.

Post by Buchi »

Professor,
When I try to compile mme program I keep getting the error message that I have an unterminated DO in line 12...and I don't.

This is the exact DO loop that its refferring to, do u see any problems with it?

do 9 i =.1,1.0,.1
print 8, i, sin(i),mysine(i),abs((1.0-(mysine(i)/sin(i))))*100.0
continue
8 format(f5.2,d18.10,d18.10,' ',d10.2)
9 end
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 8, due November 13, 2008.

Post by goodwine »

Buchi wrote:Professor,
When I try to compile mme program I keep getting the error message that I have an unterminated DO in line 12...and I don't.

This is the exact DO loop that its refferring to, do u see any problems with it?

do 9 i =.1,1.0,.1
print 8, i, sin(i),mysine(i),abs((1.0-(mysine(i)/sin(i))))*100.0
continue
8 format(f5.2,d18.10,d18.10,' ',d10.2)
9 end
What does the "continue" continue. The statement label for 9 is at "end".
Bill Goodwine, 376 Fitzpatrick
Buchi

Re: Homework 8, due November 13, 2008.

Post by Buchi »

i just noticed that the tabs and spaces were omitted but I'm pretty sure that I have them in the proper columns in my program

Buchi
Buchi

Re: Homework 8, due November 13, 2008.

Post by Buchi »

Okay thank...that worked
eward3

Re: Homework 8, due November 13, 2008.

Post by eward3 »

Eric Ward
You do not have the required permissions to view the files attached to this post.
eward3

Re: Homework 8, due November 13, 2008.

Post by eward3 »

sorry i posted it on the wrong one. I reposted with the other homework uploads
Post Reply

Return to “AME 20214, Homework 8”