Question

Hello,

Could you please see the attached question?

Physics 800 Assignment 1 Given: January 6, 2017 Due: February 6, 2017 Problems 1: 4, 11, 13. 4. A rectangular trough of infinite length and cross sectional dimensions of a 1.0 cm, b 2.0 cm, is shown in the figure. Three sides are grounded, and the top side is held at 100 V ap (a) write a fortran or c++ program to solve Laplaces equation using the finite ele ment method. Divide the region into 50 equally sized triangles. If it is useful to you, a fortran matrix inversion suboutine is attached. (b) Compare the finite element solution to the exact solution (found via separation of variables in rectangular co-ordinates of 4Va Sin 2k 1 n sinh

0 0
Add a comment Improve this question Transcribed image text
Answer #1

(A)

//code

#include<iostream>
#include<cmath>
#include<fstream>
using namespace std;
int main()
{

   float V[20][20], V0[18][18], diff[18][18];
   int i, j;

   for (i=0;i<=19;i++)
   {
       for (j=0;j<=19;j++)
       {
           V[0][j] = 0.0;
       V[19][j] = 1.0;
       V[0] = (i)/19.0;
           V[19] = (i)/19.0;
       }
   }

   for (i=1; i<=18; i++)
   {
       for (j=1; j<=18; j++)
       {
           V[j]=1.0;
       }
   }

   float maxdiff, sum, diffsum;
   int count=0;
   for(i=1;i<=18;i++)
   {
       for(j=1; j<=18; j++)
       {
           diff[j]=1.0;
       }
   }

   maxdiff=0.0001;
   diffsum=1.0;
   while (diffsum >= maxdiff)
   {
       sum = 0.0;
       for (i=1; i<=18; i++)
       {
           for (j=1; j<=18; j++)
           {
               V0[j] = V[j];  
               V[j] = ((V[i+1][j] + V[i-1][j] + V[j+1] + V[j-1])/4.0);
           diff[j] = (V0[j] - V[j]);
sum = sum + diff[j];  
           }
       }
       diffsum=sum/(18 * 18);
       count++;
   }
   cout<< count;
}

Add a comment
Know the answer?
Add Answer to:
Hello, Could you please see the attached question? Given: January 6, 2017 Due: February 6, 2017...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT