Page 1 of 1
Homework 7, due November 11, 2010.
Posted: Fri Nov 05, 2010 1:40 pm
by goodwine
Please don't upload your programs by replying here. Do it in the uploads topic.
Reading: The chapter on functions and 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 7, due November 11, 2010.
Posted: Fri Nov 05, 2010 9:58 pm
by edochert
Professor, is there any special way to declare functions as double precision? I am wondering because when I declare the arguments and the function as real values I get the desired result, but when I switch to double precision the values are passed as zeros to my function. Any ideas?
Re: Homework 7, due November 11, 2010.
Posted: Fri Nov 05, 2010 10:00 pm
by goodwine
edochert wrote:Professor, is there any special way to declare functions as double precision? I am wondering because when I declare the arguments and the function as real values I get the desired result, but when I switch to double precision the values are passed as zeros to my function. Any ideas?
Is everything declared as double precision, even the arguments that go into computing it? If that doesn't work, email your code to me.
Re: Homework 7, due November 11, 2010.
Posted: Sun Nov 07, 2010 6:33 pm
by jrumpza
Professor,
Should we upload/print out programs for each of the individual exercises or just turn in a piece of paper indicating what happens?
Re: Homework 7, due November 11, 2010.
Posted: Sun Nov 07, 2010 9:19 pm
by goodwine
jrumpza wrote:Professor,
Should we upload/print out programs for each of the individual exercises or just turn in a piece of paper indicating what happens?
You don't have to print it out for everything.
Re: Homework 7, due November 11, 2010.
Posted: Mon Nov 08, 2010 5:34 pm
by mmarszow
Professor,
For the mysine function, should we allow the function user to input the number of terms to carry out the approximation to, or should we just pick an arbitrary number?
Re: Homework 7, due November 11, 2010.
Posted: Mon Nov 08, 2010 6:03 pm
by goodwine
mmarszow wrote:Professor,
For the mysine function, should we allow the function user to input the number of terms to carry out the approximation to, or should we just pick an arbitrary number?
Don't pick an arbitrary number. Experiment to find a number that gives a good answer but doesn't loop through stuff unnecessarily.
Re: Homework 7, due November 11, 2010.
Posted: Mon Nov 08, 2010 7:46 pm
by jgalezie
Could you please post the programs from last Thursday's class? Thanks.
John Galeziewski
Re: Homework 7, due November 11, 2010.
Posted: Mon Nov 08, 2010 8:37 pm
by goodwine
jgalezie wrote:Could you please post the programs from last Thursday's class? Thanks.
I posted them last Thursday. If they aren't there, let me know because that means the link disappeared.
Re: Homework 7, due November 11, 2010.
Posted: Tue Nov 09, 2010 3:16 am
by zharris
Prof,
I am having a similar problem to edochert above. My Collaborative program will run fine when everything is set as real but when I change it to double precision, it won't work. I think it might be having issues getting into the subprograms because it doesn't print out anything from inside of them. Do you know why this is?
Thanks
Re: Homework 7, due November 11, 2010.
Posted: Tue Nov 09, 2010 6:51 am
by goodwine
zharris wrote:Prof,
I am having a similar problem to edochert above. My Collaborative program will run fine when everything is set as real but when I change it to double precision, it won't work. I think it might be having issues getting into the subprograms because it doesn't print out anything from inside of them. Do you know why this is?
Thanks
You need to declare any variables you use in the function, including the variables you pass as arguments, as double precision both in the function and in the main program.
Re: Homework 7, due November 11, 2010.
Posted: Tue Nov 09, 2010 3:53 pm
by sschwane
Professor Goodwine,
My program seems to be working correctly when I use a double precision function for MYSINE. However, as soon as I try to implement a factorial function into the MYSINE function, it starts giving me different values. I declared the variables inside the factorial function and the code in the factorial function is exactly the same as it was before I moved it out of the MYSINE function. Do you have any ideas as to why it's not working?
Thanks
Re: Homework 7, due November 11, 2010.
Posted: Tue Nov 09, 2010 4:41 pm
by goodwine
sschwane wrote:Professor Goodwine,
My program seems to be working correctly when I use a double precision function for MYSINE. However, as soon as I try to implement a factorial function into the MYSINE function, it starts giving me different values. I declared the variables inside the factorial function and the code in the factorial function is exactly the same as it was before I moved it out of the MYSINE function. Do you have any ideas as to why it's not working?
Thanks
Are you declaring everything you are using in every function? I'd recommend just declaring everything everywhere.
Re: Homework 7, due November 11, 2010.
Posted: Tue Nov 09, 2010 5:18 pm
by zharris
Prof,
When you ask us to give the nonmodified mysine and integer argument and fact a double precision argument, do you mean to just add an extra variable to definition of the function of the specified type such as: 'FUNCTION fact (double precision)' or to call the function in our main program using a variable of the specified type?
Thanks
Re: Homework 7, due November 11, 2010.
Posted: Tue Nov 09, 2010 6:40 pm
by goodwine
zharris wrote:Prof,
When you ask us to give the nonmodified mysine and integer argument and fact a double precision argument, do you mean to just add an extra variable to definition of the function of the specified type such as: 'FUNCTION fact (double precision)' or to call the function in our main program using a variable of the specified type?
Thanks
No, I don't mean to add a variable. I mean to try to use it with the wrong type of argument and say whether the compiler says something or something goes wrong when you run it or if everything seems ok.
Re: Homework 7, due November 11, 2010.
Posted: Wed Nov 10, 2010 8:58 pm
by fvisovsk
Frank Visovsky
HW 7 upload
Re: Homework 7, due November 11, 2010.
Posted: Thu Nov 11, 2010 11:46 am
by cjosephs
Heres the stuff