Page 1 of 1
Homework 3, due September 30, 2010.
Posted: Thu Sep 23, 2010 8:58 am
by goodwine
Reading: Chapter 3 from the course text.
Collaborative Exercises:
- Assume that you entered the value -0.00123456789 and assigned it to the real variable X and then subsequently printed it useing
How would the output appear for each of the following FORMAT statements
- Write a computer program that computes the area of a triangle. The user should input the (x,y) values of the three points. A good program would check that the user entered three different points. The program should ouput
- The (x,y) values entered with three digits after the decimal point for each value. Each (x,y) pair should be on a new line.
- The area with one digit after the decimal point.
- The area in exponential notation.
Everything that is printed should have some text preceding it to indicate what is being printed.
Individual Exercise:
Modify your sine function based on a Taylor series to output a table. The first column of the table should be angle values that go from -90 degrees to +90 degrees in increments of 10 degrees. The second column should be the correct value for the sine function (you may use the SIN() fortran function for that column. The third through seventh columns should be what your Taylor series computes for 1, 2, 3, 4 and 5 terms, respectively. Each column should have a label at the top. The number of digits printed should be appropriate to effectively communicate the accuracy of the Taylor series approximations and the decimal points, if present, should line up in each column.
In other words, make the table one of professional quality, as if your job depended on it.
After your program runs properly, run it by typing
a.out > output.txt
This will "redirect" the output of the program to be put in the file "output.txt" instead of being printed to the screen. Print out the file and submit it with your homework.
Re: Homework 3, due September 30, 2010.
Posted: Sun Sep 26, 2010 4:24 pm
by wnichol4
For the individual part, in HW 1 we did the cosine function for homework, and you did the sine function is class. Which do you want us to use?
Re: Homework 3, due September 30, 2010.
Posted: Sun Sep 26, 2010 5:31 pm
by goodwine
wnichol4 wrote:For the individual part, in HW 1 we did the cosine function for homework, and you did the sine function is class. Which do you want us to use?
Since I didn't specify it, either one is ok.
Re: Homework 3, due September 30, 2010.
Posted: Sun Sep 26, 2010 7:13 pm
by nd13
For collaborative problem 1 part k, should there be a comma instead of a period in front of T10? You typed a period, which gives an error when it gets compiled. A comma makes it work.
Re: Homework 3, due September 30, 2010.
Posted: Sun Sep 26, 2010 8:12 pm
by goodwine
nd13 wrote:For collaborative problem 1 part k, should there be a comma instead of a period in front of T10? You typed a period, which gives an error when it gets compiled. A comma makes it work.
The correct answer then would be that it won't work. Since you figured it out, you might as well say what happens with the comma.
Re: Homework 3, due September 30, 2010.
Posted: Mon Sep 27, 2010 5:46 pm
by jszczudl
For the collaborative, can we do all of the parts in one program and label then differently. For example, can we put:
13 format (f12.3)
print 13, x
14 format (f10.3)
print 14, x
etc....?
Re: Homework 3, due September 30, 2010.
Posted: Mon Sep 27, 2010 6:00 pm
by jszczudl
and then just comment out the one that we don't want to compile?
That way I don't have to upload a lot of programs.
Re: Homework 3, due September 30, 2010.
Posted: Mon Sep 27, 2010 7:12 pm
by goodwine
jszczudl wrote:and then just comment out the one that we don't want to compile?
That way I don't have to upload a lot of programs.
Yes, to this question and the one above.
Re: Homework 3, due September 30, 2010.
Posted: Mon Sep 27, 2010 8:28 pm
by jszczud1
Collaborative Problem #1 e and i, are the same thing if I'm not mistaken. Was there some other point you were trying to make with these to formats and accidentally typed them wrong?
Re: Homework 3, due September 30, 2010.
Posted: Mon Sep 27, 2010 8:52 pm
by goodwine
jszczud1 wrote:Collaborative Problem #1 e and i, are the same thing if I'm not mistaken. Was there some other point you were trying to make with these to formats and accidentally typed them wrong?
That was a mistake. Just treat them as the same.
Re: Homework 3, due September 30, 2010.
Posted: Mon Sep 27, 2010 11:32 pm
by jszczud1
Also for the second collaborative problem what would be a reasonable amount of spaces to allow for the coordinates?
Re: Homework 3, due September 30, 2010.
Posted: Tue Sep 28, 2010 5:51 am
by goodwine
jszczud1 wrote:Also for the second collaborative problem what would be a reasonable amount of spaces to allow for the coordinates?
I'm not sure I understand the question. I think the coordinates should be unlimited.
Re: Homework 3, due September 30, 2010.
Posted: Tue Sep 28, 2010 2:10 pm
by jszczud1
goodwine wrote:jszczud1 wrote:Also for the second collaborative problem what would be a reasonable amount of spaces to allow for the coordinates?
I'm not sure I understand the question. I think the coordinates should be unlimited.
Oh, because I can't figure out a way to allow for an unlimited amount of numbers before a decimal place and have a limited number after.
Re: Homework 3, due September 30, 2010.
Posted: Tue Sep 28, 2010 3:10 pm
by goodwine
jszczud1 wrote:goodwine wrote:jszczud1 wrote:Also for the second collaborative problem what would be a reasonable amount of spaces to allow for the coordinates?
I'm not sure I understand the question. I think the coordinates should be unlimited.
Oh, because I can't figure out a way to allow for an unlimited amount of numbers before a decimal place and have a limited number after.
You don't know what the user will input, so use free format for the read. What I want you to format is the answer.
Re: Homework 3, due September 30, 2010.
Posted: Tue Sep 28, 2010 5:45 pm
by jrumpza
Because the Taylor series alternates, every other term is 0, so then if you have t=2 for the taylor series of the cosine function, you will get the same answer as t=3. So for our table when you said to compute the number for 1,2,3,4,5 terms, did you mean t=1,2,3,4,5 or t=2,4,6,8,10 so it actually adds 5 different non-zero terms? With using simply t=1,2,3,4,5, the columns for t=2 and t=3 are identical, as well as for t=4 and t=5. I assume you want each column different, but I just want to make sure.
Re: Homework 3, due September 30, 2010.
Posted: Tue Sep 28, 2010 5:56 pm
by goodwine
jrumpza wrote:Because the Taylor series alternates, every other term is 0, so then if you have t=2 for the taylor series of the cosine function, you will get the same answer as t=3. So for our table when you said to compute the number for 1,2,3,4,5 terms, did you mean t=1,2,3,4,5 or t=2,4,6,8,10 so it actually adds 5 different non-zero terms? With using simply t=1,2,3,4,5, the columns for t=2 and t=3 are identical, as well as for t=4 and t=5. I assume you want each column different, but I just want to make sure.
Since I didn't word the problem well, either way will receive full credit. However, what I really wanted was for each column to be different.
Re: Homework 3, due September 30, 2010.
Posted: Tue Sep 28, 2010 7:58 pm
by astumpf
For Collaborative Problem Number 2, can we use a Go To function at all? If not, is there some other way for us to restart/cancel our program?
Re: Homework 3, due September 30, 2010.
Posted: Tue Sep 28, 2010 8:00 pm
by goodwine
astumpf wrote:For Collaborative Problem Number 2, can we use a Go To function at all? If not, is there some other way for us to restart/cancel our program?
It's ok to use a goto to send the program back to the point where they enter the points if they don't enter three different points.
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 1:01 am
by zharris
Can we answer the questions by commenting our code?
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 6:00 am
by goodwine
zharris wrote:Can we answer the questions by commenting our code?
Sure.
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 6:03 am
by goodwine
Someone asked me:
or the individual problem in this week's homework, does FORTRAN read the number that we put into its 'sin()' function in radians or degrees? If it does read it in terms of radians, should we convert our angles to match it? Thanks.
I think it's radians, but can't say for sure. Write a two-line program to find out for sure.
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 1:25 pm
by jwoodru1
I tried to export the resulting table using the a.out>output.txt but when I open the .txt file it is all on two lines. Is there a way to fix this?
Thanks
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 2:11 pm
by goodwine
jwoodru1 wrote:I tried to export the resulting table using the a.out>output.txt but when I open the .txt file it is all on two lines. Is there a way to fix this?
I'm sure there is a way to fix it, but without any more information I can't really be of much help.
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 5:38 pm
by joneill5
For Collaborative Problem 1, do you want us to have the long decimal directly in the code, or do you want us to set it up as a user input?
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 6:50 pm
by goodwine
joneill5 wrote:For Collaborative Problem 1, do you want us to have the long decimal directly in the code, or do you want us to set it up as a user input?
Either way is fine.
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 8:13 pm
by goodwine
Someone asked me
am writing a program, trying to use and if then statement, and when I write one thing in quotes the program works,
but when I write something else the terminal gives me
PGFTN-S-0026-Unmatched quote (hw3p2.f: 29)
This is for determining if it is a triangle.
Should I just comment it out and ignore it?
I suspect the line is too long, so the compiler isn't seeing the last quotation mark.
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 8:44 pm
by joneill5
For some reason, the square root function is causing an error message. Any idea why?
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 8:46 pm
by goodwine
joneill5 wrote:For some reason, the square root function is causing an error message. Any idea why?
Without any more information, my only guess is that it's argument is negative?
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 8:49 pm
by joneill5
goodwine wrote:joneill5 wrote:For some reason, the square root function is causing an error message. Any idea why?
Without any more information, my only guess is that it's argument is negative?
The message is "Symbol, sqrt, has not been explicitly declared"
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 9:03 pm
by goodwine
joneill5 wrote:goodwine wrote:joneill5 wrote:For some reason, the square root function is causing an error message. Any idea why?
Without any more information, my only guess is that it's argument is negative?
The message is "Symbol, sqrt, has not been explicitly declared"
Is it's argument real, as opposed to an integer?
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 9:07 pm
by joneill5
I've listed the variables as integers. Should they be listed as reals instead?
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 9:08 pm
by goodwine
joneill5 wrote:I've listed the variables as integers. Should they be listed as reals instead?
I don't know why you are taking a square root, but sqrt(3.0) works, but sqrt(3) does not.
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 9:08 pm
by joneill5
Never mind, they have to be listed as reals. Thanks.
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 9:10 pm
by joneill5
goodwine wrote:joneill5 wrote:I've listed the variables as integers. Should they be listed as reals instead?
I don't know why you are taking a square root, but sqrt(3.0) works, but sqrt(3) does not.
For Collaborative problem 2, it asks you to let the user input the different coordinates. I had listed all of the variables for this problem as integers, but it didn't work. When you asked if they were reals or integers, I changed them all to reals and it worked.
I needed the square roots for the distance between points so I could use Heron's Formula.
Re: Homework 3, due September 30, 2010.
Posted: Wed Sep 29, 2010 9:26 pm
by goodwine
joneill5 wrote:goodwine wrote:joneill5 wrote:I've listed the variables as integers. Should they be listed as reals instead?
I don't know why you are taking a square root, but sqrt(3.0) works, but sqrt(3) does not.
For Collaborative problem 2, it asks you to let the user input the different coordinates. I had listed all of the variables for this problem as integers, but it didn't work. When you asked if they were reals or integers, I changed them all to reals and it worked.
I needed the square roots for the distance between points so I could use Heron's Formula.
I see. I thought it was for the table for the Taylor series problem.