Question

Code that needs to be modified: #include <stdio.h> #include <math.h> int main(void) { FILE * fileout; int ix,iy,it,Nt; double newV[31][21],V[31][21],x,dx,y,dy; fileout=fopen("buckbeak....

Code that needs to be modified:

#include <stdio.h>

#include <math.h>

int main(void)

{

FILE * fileout;

int ix,iy,it,Nt;

double newV[31][21],V[31][21],x,dx,y,dy;

fileout=fopen("buckbeak.dat","w");

printf("\nEnter number of iterations ");

scanf("%d",&Nt);

dx=0.10;

dy=0.10;

  

for(iy=0; iy<21; iy=iy+1)

{

for(ix=0; ix<31; ix=ix+1)

{

V[ix][iy]=0.0;

}

}

iy=20;

for (ix=0;ix<31; ix=ix+1)

   {

   V[ix][iy]=8.0;

   }

for (it=0; it<Nt;it=it+1)

{

for(iy=1; iy<20;iy=iy+1)

{

for(ix=1;ix<30; ix=ix+1)

{

newV[ix][iy]=0.25*(V[ix+1][iy]+V[ix-1][iy]+V[ix][iy+1]+V[ix][iy-1]);

}

}

for (iy=1; iy<20; iy=iy+1)

{

for(ix=1; ix<30; ix=ix+1)

{

V[ix][iy]=newV[ix][iy];

}

}

  

}

for (iy=0;iy<21;iy=iy+1)

{

y=dy*iy;

for (ix=0;ix<31;ix=ix+1)

{

x=dx*ix;

fprintf(fileout,"\n %8.4lf %8.4lf %8.4lf",x,y,V[ix][iy]);

}

fprintf(fileout,"\n");

}

printf("\n V at box center %12.6lf", V[15][10]);

fclose(fileout);

printf("\n");

return 0;

}

Question: In wht array elements are the values of the potential on the boundaries stored? Why do the ix loops go to 30 or 31 . while the iy loops go to 20 or 21? Why do some of the ix loops go to 31 and others to 30

******* Please make sure you answer all the questions asked and please do it 100%correctly. Please write neat and very clear that way i can be able to read and understand what is being said. The language used is C.

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

Okay I am going to explain you How this code is working. why the loops are 1. 2. o starting from 0 AND ending on (21 OR 31) o

Now, 2ndly how are the loops working. Before that you must know that, indexes in programming start with 0 and end on 1 less t

LOOP-2 20; This loop will set value 8, in the whole last column [20] of the matrix. The 2D-Array will look like this after ex

LOOP-3 The outer it loop will run Nt Times Now why are the inner loops starting from 1 and ending on 20 or 30? The inner loLOOP-4 forinttifileout, \n %8.41f %8.41fX8.41f, v[1x][ǐy] ); x, y, tpcinttitileout, \n); This loop is pretty much the sam

for any query leave a comment here ill get back to you as soon as possible :)

PLEASE DO NOT FORGET TO LEAVE A THUMBS UP! THANKS! :)

Add a comment
Know the answer?
Add Answer to:
Code that needs to be modified: #include <stdio.h> #include <math.h> int main(void) { FILE * fileout; int ix,iy,it,Nt; double newV[31][21],V[31][21],x,dx,y,dy; fileout=fopen("buckbeak....
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