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
  • Convert this code from C to C++ include <stdio.h> include <locale.h> void filtre (double x. double yll, double yol, int , int N) int Nn-10000 int main) setlocale (LC ALL,") double...

    Convert this code from C to C++ include <stdio.h> include <locale.h> void filtre (double x. double yll, double yol, int , int N) int Nn-10000 int main) setlocale (LC ALL,") double x(Nm) , y [ Nm],yo Nml®(0.0); int m; FILE dosyal-fopen("D:/veri/673.txtr FILE dosya2-fopen("D:/veri/data2.txt int i-0 while( feof (dosyal)) fscanf (dosyal, " ",xi sytil) fclose (dosyal) int Nij printf("Pencere Genişligi scanf() 3 filtre(x,y.Yo,m,N) for(int k-0keNkt+)fprintf (dosya2, 10.41 10.411 0.41fn",x[k],y[k].yo[k]) fclose(dosya2) void filtre (double x double y. double yoll, int m, int...

  • convert this code from C to C++ include <stdio.h> include <locale.h> void filtre (double x. double...

    convert this code from C to C++ include <stdio.h> include <locale.h> void filtre (double x. double yll, double yol, int , int N) int Nn-10000 int main) setlocale (LC ALL,") double x(Nm) , y [ Nm],yo Nml®(0.0); int m; FILE dosyal-fopen("D:/veri/673.txtr FILE dosya2-fopen("D:/veri/data2.txt int i-0 while( feof (dosyal)) fscanf (dosyal, " ",xi sytil) fclose (dosyal) int Nij printf("Pencere Genişligi scanf() 3 filtre(x,y.Yo,m,N) for(int k-0keNkt+)fprintf (dosya2, 10.41 10.411 0.41fn",x[k],y[k].yo[k]) fclose(dosya2) void filtre (double x double y. double yoll, int m, int...

  • Code that needs to be modified: #include #include #include int main() { int i,N,x; unsigned int seed; double R; printf("\nEnter number of iterations and seed"); printf("\n"); scanf(&#3...

    Code that needs to be modified: #include #include #include int main() { int i,N,x; unsigned int seed; double R; printf("\nEnter number of iterations and seed"); printf("\n"); scanf("%i %u", &N,&seed); srand(seed);    for(i=0;i { R=(double)rand()/RAND_MAX; if (R<0.5) x=x+1; else x=x-1; } printf("Final location is "); printf("%d",x); printf("\n"); } Question: Write a code that generates N pairs of random numbers. Call the first member of each pair x and the second member y. Count how many of the N pairs obey x^2+y^2<1. Call...

  • lab3RGB.c file: #include <stdio.h> #define AlphaValue 100 int main() { int r, g,b; unsigned int rgb_pack...

    lab3RGB.c file: #include <stdio.h> #define AlphaValue 100 int main() { int r, g,b; unsigned int rgb_pack; int r_unpack, g_unpack,b_unpack; int alpha = AlphaValue; printf("enter R value (0~255): "); scanf("%d",&r); printf("enter G value (0~255): "); scanf("%d",&g); printf("enter B value (0~255): "); scanf("%d",&b); while(! (r<0 || g<0 || b <0) ) { printf("A: %d\t", alpha); printBinary(alpha); printf("\n"); printf("R: %d\t", r); printBinary(r); printf("\n"); printf("G: %d\t", g); printBinary(g); printf("\n"); printf("B: %d\t", b); printBinary(b); printf("\n"); /* do the packing */ //printf("\nPacked: value %d\t", rgb_pack); printBinary(rgb_pack);printf("\n");...

  • the code in the photo for this I.V.P dy/dx= x+y. y(0)=1 i need the two in the photo thank you New folder Bookmark...

    the code in the photo for this I.V.P dy/dx= x+y. y(0)=1 i need the two in the photo thank you New folder Bookmarks G Google dy/dx x+y, y(0)=1 2 h Exact Solution 1.8 Approximate Solution Mesh Points 1.6 -Direction Fied 1.4 1.2 1 0.8 04 0.2 0.3 0.1 0 X CAUsersleskandara\Desktop\New folder emo.m EDITOR PUBLISH VEW Run Section FILE NAVIGATE EDIT Breakpoints Run Run and FL Advance Run and Advance Time BREAKPOINTS RUN 1 - clear all 2 clc 3-...

  • Question 2 - Programming Exercise 1. Make a directory for this lab and change into it....

    Question 2 - Programming Exercise 1. Make a directory for this lab and change into it. 2. Copy files using the following command: cp/net/data/ftp/pub/class/115/ftp/cpp/Inheritance/Exercise.cpp Exercise.cpp Finish the program so that it compiles and runs. The instructions are contained in the C++ file. Your completed program should generate output similar to the following: TwoD default constructor This program asks for the coordinates of two points in 3D space and calculates their distance. Please enter the xyz coordinates for the first point:...

  • okay so here is my c++ code and the errors im really stuck on fixing what...

    okay so here is my c++ code and the errors im really stuck on fixing what i did wrong it seems to be the same repeated error our job is to write a menu driven program that can convert to display Morse Code ere is the menu the program should display Menu Alphabet Initials N-Numbers - Punctuations S = User Sentence Q- Quit Enter command the user chooses A your program should use a loop and your morse code printing...

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