lab3 presentation grup b2
TRANSCRIPT
LAB3: FIELD PLOTTING-FINITE DIFFERENCES(ITERATION METHOD)
PRESENTATION BY: BOSA T. NTSHOLEGROUP MEMBERS:ONTSE MOFENYI
TAPOLOGO RAMASESANEKEONE OALOTSE
WHAT WAS THE LAB ABOUT?
• To use a numerical method (finite-differences) to plot a field for a given configuration of conductor boundaries with the aid of a digital computer(C++ SOFTWARE) which was used to calculate potentials at specified lattice points in a field.
• Our mandate was to perform Q9 and Q11 on Engineering Electromagnetics 6th Edition - William H. Hayt, John A. Buck._chapter 6.
HOW THE LAB WAS CARRIED OUT
• A C++ program was generated such that the outcomes are as expected.
• For question 9, a corresponding C++ program was used to set the matrix of 9 by 9 triangular trough lattice points.
• On question 11, also a corresponding C++ program was made such that an irregular lattice points were generated having matrix of 6 by 11.
EQUATION USED TO FIND POTENTIAL AT REQUIRED LATTICE POIN
EQUATION USED TO FIND POTENTIAL AT REQUIRED LATTICE POINT
• This equation gives the potential required at a specified location as
•
V0 =
PREFFERENCE
• Using a digital computer to find the potential at specified lattice point is more accurate than using the equation on the previous slide.
• This is so because accuracy can be set on the program source code.
EXPECTED RESULTS
RESULTS FOR Q11A
DISCUSSION OF RESULTS OBTAINED
• Gap voltages ( pair of 30V) were obtained by averaging the sum of top plate voltage(0V) and the slanting plate voltage(60V).
• We can observe symmetry along column 5 of our lattice points.
• Also the V-shaped dent was acquired. This was done by removing unwanted zeroes to perfectly identify our plate boundaries.
DISCUSSION OF RESULTS OBTAINED
• The unwanted zeroes were removed by setting our source code to skip/ignore the specified points on the matrix.
• This was achieved using an if statement.
C++ PROGRAMS USED FOR THE LAB
•APPENDIX 1•
•#include <stdio.h>
•#include <math.h>
•#include<iostream>
•#define MSIZER 9
•#define MSIZEC 9
•float a[MSIZER][MSIZEC],
•b[MSIZER][MSIZEC],
•c;
•int i, j;
•void print(void);
•int main(void)
•{
•
• for (i = 0; i<MSIZER; ++i) {
• for (j = 0; j<MSIZEC; ++j) {
C++ PROGRAMS USED FOR THE LAB• a[i][j] = 0.;
• }
• }
•
•
• for (i = 0; i<MSIZER; ++i) {
• for (j = 0; j<MSIZEC; ++j) {
• a[0][0] = 50;
• a[1][1] = 100;
• a[2][2] = 100;
• a[3][3] = 100;
• a[4][4] = 100;
• a[5][5] = 100;
• a[6][6] = 100;
• a[7][7] = 100;
• a[8][8] = 50;
• }
C++ PROGRAMS USED FOR THE LAB• }
•
•again:
• //print(); getchar();
•
•
• for (i = 2; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<2; ++j) { // column
• a[i][j] = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• }
• }
• for (i = 3; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<3; ++j) { // column
• a[i][j] = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• }
• }
• for (i = 4; i<MSIZER - 1; ++i) { // row
C++ PROGRAMS USED FOR THE LAB• for (j = 1; j<4; ++j) { // column
• a[i][j] = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• }
• }
• for (i = 5; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<5; ++j) { // column
• a[i][j] = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• }
• }
• for (i = 6; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<6; ++j) { // column
• a[i][j] = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• }
• }
• for (i = 7; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<7; ++j) { // column
• a[i][j] = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• }
C++ PROGRAMS USED FOR THE LAB• }
•
• // determine residual for stop condition
• for (i = 2; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<2; ++j) { // column
• c = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• b[i][j] = a[i][j] - c; // previous potential - new one
• if ((fabs(b[i][j]) - 0.00001)>.0) goto again; // stop diff < 0.00001
• }
• }
• for (i = 3; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<3; ++j) { // column
• c = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• b[i][j] = a[i][j] - c; // previous potential - new one
• if ((fabs(b[i][j]) - 0.00001)>.0) goto again; // stop diff < 0.00001
• }
• }
C++ PROGRAMS USED FOR THE LAB•
• for (i = 4; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<4; ++j) { // column
• c = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• b[i][j] = a[i][j] - c; // previous potential - new one
• if ((fabs(b[i][j]) - 0.00001)>.0) goto again; // stop diff < 0.00001
• }
• }
• for (i = 5; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<5; ++j) { // column
• c = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• b[i][j] = a[i][j] - c; // previous potential - new one
• }
• }
• for (i = 6; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<6; ++j) { // column
• c = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• b[i][j] = a[i][j] - c; // previous potential - new one
C++ PROGRAMS USED FOR THE LAB• }
• }
• for (i = 7; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<7; ++j) { // column
• c = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• b[i][j] = a[i][j] - c; // previous potential - new one
• }
• }
• print(); getchar();
•
•}
•void print(void) {
•
• for (i = 0; i < MSIZER; ++i)
• { // row
• for (j = 0; j < MSIZEC; ++j) { // column
• if ((i == 0)&(j == 1) || (i == 0)&(j == 2) || (i == 0)&(j == 3) || (i == 0)&(j == 4) || (i == 0)&(j == 5) || (i == 0)&(j == 6) || (i == 0)&(j == 7) || (i == 0)&(j == 8) ||
C++ PROGRAMS USED FOR THE LAB• (i == 1)&(j == 2) || (i == 1)&(j == 3) || (i == 1)&(j == 4) || (i == 1)&(j == 5) || (i == 1)&(j == 6) || (i == 1)&(j == 7) || (i == 1)&(j == 8) ||
• (i == 2)&(j == 3) || (i == 2)&(j == 4) || (i == 2)&(j == 5) || (i == 2)&(j == 6) || (i == 2)&(j == 7) || (i == 2)&(j == 8) ||
• (i == 3)&(j == 4) || (i == 3)&(j == 5) || (i == 3)&(j == 6) || (i == 3)&(j == 7) || (i == 3)&(j == 8)||
• (i == 4)&(j == 5) || (i == 4)&(j == 6) || (i == 4)&(j == 7) || (i == 4)&(j == 8)||
• (i == 5)&(j == 6) || (i == 5)&(j == 7) || (i == 5)&(j == 8)||
• (i == 6)&(j == 7) || (i == 6)&(j == 8)||
• (i == 7)&(j == 8)){
• printf(" ");
• continue;
• }
• printf(" %5.1f", a[i][j]);
• }
• printf("\n\n");
• }
•}
•
•
•
C++ PROGRAMS USED FOR THE LAB
•APPENDIX 2•
•#include <stdio.h>
•#include <math.h>
•#include<iostream>
•#define MSIZER 6
•#define MSIZEC 11
•float a[MSIZER][MSIZEC],
•b[MSIZER][MSIZEC],
•c;
•int i, j;
•void print(void);
•int main(void)
•{
•
• for (i = 0; i < MSIZER; ++i) {
C++ PROGRAMS USED FOR THE LAB• for (j = 0; j < MSIZEC; ++j) {
• a[i][j] = 0.;
• }
• }
• for (j = 0; j < 3; ++j){
• a[0][j] = 0.;
• }
• for (j = 8; j>7; ++j){
• a[0][j] = 0.;
• }
• for (j = 0; j < MSIZEC; ++j){
• a[5][j] = 0.;
• }
• for (j = 0; j < MSIZEC; ++j){
• a[5][j] = 0.;
• }
•
• for (j = 0; i < MSIZER; ++i) {
C++ PROGRAMS USED FOR THE LAB• for (j = 0; j < MSIZEC; ++j) {
• a[0][3] = 30.;
• a[0][7] = 30.;
• a[1][4] = 60.;
• a[2][5] = 60.;
• a[1][6] = 60.;
• }
• }
•
•again:
• //print(); getchar();
•
•
• for (i = 1; i<MSIZER - 1; ++i) { // row
• for (j = 1; j < 4; ++j)
• { // column
• a[i][j] = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
C++ PROGRAMS USED FOR THE LAB• }
• for (i = 1; i < MSIZER - 1; ++i)
• for (j = 7; j < 10; ++j){
• a[i][j] = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
•
• }
• }
• for (i = 2; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<5; ++j) { // column
• a[i][j] = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• }
• for (i = 2; i < MSIZER - 1; ++i)
• for (j = 6; j < 10; ++j){
• a[i][j] = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
•
• }
• }
• for (i = 3; i<MSIZER - 1; ++i) { // row
C++ PROGRAMS USED FOR THE LAB• for (j = 1; j<10; ++j) { // column
• a[i][j] = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• }
• }
• for (i = 4; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<10; ++j) { // column
• a[i][j] = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• }
• }
•
•
• // determine residual for stop condition
• for (i = 0; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<0; ++j) { // column
• c = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• b[i][j] = a[i][j] - c; // previous potential - new one
• if ((fabs(b[i][j]) - 0.00001)>.0) goto again; // stop diff < 0.00001
C++ PROGRAMS USED FOR THE LAB• }
• }
• for (i = 1; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<1; ++j) { // column
• c = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• b[i][j] = a[i][j] - c; // previous potential - new one
• if ((fabs(b[i][j]) - 0.00001)>.0) goto again; // stop diff < 0.00001
• }
• }
•
• for (i = 2; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<2; ++j) { // column
• c = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• b[i][j] = a[i][j] - c; // previous potential - new one
• if ((fabs(b[i][j]) - 0.00001)>.0) goto again; // stop diff < 0.00001
• }
• }
• for (i = 3; i<MSIZER - 1; ++i) { // row
C++ PROGRAMS USED FOR THE LAB• for (j = 1; j<3; ++j) { // column
• c = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• b[i][j] = a[i][j] - c; // previous potential - new one
• }
• }
• for (i = 4; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<4; ++j) { // column
• c = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• b[i][j] = a[i][j] - c; // previous potential - new one
• }
• }
• for (i = 5; i<MSIZER - 1; ++i) { // row
• for (j = 1; j<5; ++j) { // column
• c = (a[i][j - 1] + a[i - 1][j] + a[i][j + 1] + a[i + 1][j]) / 4.;
• b[i][j] = a[i][j] - c; // previous potential - new one
• }
• }
C++ PROGRAMS USED FOR THE LAB• print(); getchar();
•
•}
•void print(void) {
•
• for (i = 0; i < MSIZER; ++i)
• { // row
• for (j = 0; j < MSIZEC; ++j) { // column
• if ((i == 0)&(j == 4) || (i == 0)&(j == 5) || (i == 0)&(j == 6) || (i == 1)&(j == 5)){
• printf(" ");
• continue;
• }
• printf(" %5.1f", a[i][j]);
• }
• printf("\n\n");
• }
•}