Page 1 of 1
Homework 8, due November 13, 2008.
Posted: Fri Nov 07, 2008 8:50 pm
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:
- has a double precision function called "mysine" that uses your series approximation from before to compute the sine of an angle;
- an integer function called "fact" that computes the factorial and is used in the sine series by the sine function;
- 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);
- 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:
- have the mysine function call itself from inside and indicate what happens;
- have mysine call fact (which it should already do) and then have fact call mysine and indicate what happens;
- give the nonmodified mysine and integer argument and fact a double precision argument and indicate what happens;
- 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.
Re: Homework 8, due November 13, 2008.
Posted: Sun Nov 09, 2008 9:35 pm
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
Re: Homework 8, due November 13, 2008.
Posted: Mon Nov 10, 2008 7:01 am
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.
Re: Homework 8, due November 13, 2008.
Posted: Mon Nov 10, 2008 5:30 pm
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
Re: Homework 8, due November 13, 2008.
Posted: Mon Nov 10, 2008 5:31 pm
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.
Re: Homework 8, due November 13, 2008.
Posted: Thu Nov 13, 2008 1:13 pm
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
Re: Homework 8, due November 13, 2008.
Posted: Thu Nov 13, 2008 1:14 pm
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".
Re: Homework 8, due November 13, 2008.
Posted: Thu Nov 13, 2008 1:14 pm
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
Re: Homework 8, due November 13, 2008.
Posted: Thu Nov 13, 2008 1:17 pm
by Buchi
Okay thank...that worked
Re: Homework 8, due November 13, 2008.
Posted: Thu Nov 13, 2008 3:08 pm
by eward3
Eric Ward
Re: Homework 8, due November 13, 2008.
Posted: Thu Nov 13, 2008 3:10 pm
by eward3
sorry i posted it on the wrong one. I reposted with the other homework uploads