Homework 3, due September 30, 2010.

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

Homework 3, due September 30, 2010.

Post by goodwine »

Reading: Chapter 3 from the course text.

Collaborative Exercises:
  1. Assume that you entered the value -0.00123456789 and assigned it to the real variable X and then subsequently printed it useing

    Code: Select all

           PRINT 13, X
    How would the output appear for each of the following FORMAT statements
    1. Code: Select all

       13   FORMAT(F12.3)
    2. Code: Select all

       13   FORMAT(F10.3)
    3. Code: Select all

       13   FORMAT(F14.5)
    4. Code: Select all

       13   FORMAT(F7.2)
    5. Code: Select all

       13   FORMAT('X=',F12.3)
    6. Code: Select all

       13   FORMAT(E12.3)
    7. Code: Select all

       13   FORMAT(D12.3)
    8. Code: Select all

       13   FORMAT(D6.3)
    9. Code: Select all

       13   FORMAT('X=',F12.3)
    10. Code: Select all

       13   FORMAT('X=',/,F12.3)
    11. Code: Select all

       13   FORMAT('X=',/.T10,F12.3)
  2. 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
    1. 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.
    2. The area with one digit after the decimal point.
    3. 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.
Bill Goodwine, 376 Fitzpatrick
wnichol4

Re: Homework 3, due September 30, 2010.

Post 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?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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.
Bill Goodwine, 376 Fitzpatrick
nd13

Re: Homework 3, due September 30, 2010.

Post 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.
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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.
Bill Goodwine, 376 Fitzpatrick
jszczudl

Re: Homework 3, due September 30, 2010.

Post 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....?
jszczudl

Re: Homework 3, due September 30, 2010.

Post 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.
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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.
Bill Goodwine, 376 Fitzpatrick
jszczud1

Re: Homework 3, due September 30, 2010.

Post 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?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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.
Bill Goodwine, 376 Fitzpatrick
jszczud1

Re: Homework 3, due September 30, 2010.

Post by jszczud1 »

Also for the second collaborative problem what would be a reasonable amount of spaces to allow for the coordinates?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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.
Bill Goodwine, 376 Fitzpatrick
jszczud1

Re: Homework 3, due September 30, 2010.

Post 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.
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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.
Bill Goodwine, 376 Fitzpatrick
jrumpza

Re: Homework 3, due September 30, 2010.

Post 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.
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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.
Bill Goodwine, 376 Fitzpatrick
astumpf

Re: Homework 3, due September 30, 2010.

Post 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?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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.
Bill Goodwine, 376 Fitzpatrick
zharris

Re: Homework 3, due September 30, 2010.

Post by zharris »

Can we answer the questions by commenting our code?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post by goodwine »

zharris wrote:Can we answer the questions by commenting our code?
Sure.
Bill Goodwine, 376 Fitzpatrick
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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.
Bill Goodwine, 376 Fitzpatrick
jwoodru1

Re: Homework 3, due September 30, 2010.

Post 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
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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.
Bill Goodwine, 376 Fitzpatrick
joneill5

Re: Homework 3, due September 30, 2010.

Post 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?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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.
Bill Goodwine, 376 Fitzpatrick
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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.
Bill Goodwine, 376 Fitzpatrick
joneill5

Re: Homework 3, due September 30, 2010.

Post by joneill5 »

For some reason, the square root function is causing an error message. Any idea why?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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?
Bill Goodwine, 376 Fitzpatrick
joneill5

Re: Homework 3, due September 30, 2010.

Post 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"
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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?
Bill Goodwine, 376 Fitzpatrick
joneill5

Re: Homework 3, due September 30, 2010.

Post by joneill5 »

I've listed the variables as integers. Should they be listed as reals instead?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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.
Bill Goodwine, 376 Fitzpatrick
joneill5

Re: Homework 3, due September 30, 2010.

Post by joneill5 »

Never mind, they have to be listed as reals. Thanks.
joneill5

Re: Homework 3, due September 30, 2010.

Post 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.
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 3, due September 30, 2010.

Post 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.
Bill Goodwine, 376 Fitzpatrick
Post Reply

Return to “AME 20214, Homework 3”