hw7_solution

hw7_solution - EME5 Homework 7 Solutions November 12, 2010...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
EME5 Homework 7 Solutions November 12, 2010 3 Chapter 10, Problem 36 3.1 Solution Code #include<stdio.h> int f(int n, int m, int a[n][m], int t[m][n]) { int i, j; for(i = 0; i < n; i++) { for(j = 0; j < m; j++) { t[j][i] = a[i][j]; } } return 0; } 4 Chapter 10, Problem 45 4.1 Solution Code #include <stdio.h> #include <numeric.h> int main() { double a[4][4] = {13.0/12, -1, 0, 0, -1, 4.0/3, 5.0/6, -0.5, 0, 1, -1, 0, 0, 0, 0, 1}; double b[4] = {14, 0, 6, -6}, i[4]; linsolve(i, a, b); printf("i[0] = %f, i[1] = %f, i[2] = %f, \ i[3] = %f amperes\n", i[0], i[1], i[2], i[3]); return 0; 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
} 4.2 Solution Output i[0] = 24.000000, i[1] = 12.000000, i[2] = 6.000000, \ i[3] = -6.000000 amperes 5 Chapter 10, Problem 50 5.1 Solution Code #include <math.h> #include <chplot.h> #define NUMX 60 #define NUMY 80 double peaks(double x, double y) { // function to be plotted return 3*(1-x)*(1-x)*exp(-(x*x) - (y+1)*(y+1) ) - 10*(x/5 - x*x*x - pow(y,5))*exp(-x*x-y*y) - 1/3*exp(-(x+1)*(x+1) - y*y); } int main() { char *title="Peaks function", *xlabel="x", \ *ylabel="y", *zlabel="z"; double x0 = -3, xf = 3, y0 = -4, yf = 4; double x[NUMX], y[NUMY], z[NUMX*NUMY]; int i, j; /* fill array y with values in the range [y0, yf] linearly */ for(j=0; j<NUMY; j++) y[j] = y0 + j*(yf-y0)/(NUMY-1); for(i=0; i<NUMX; i++) { /* fill array x with values in the range [x0, xf] linearly */ x[i] = x0 + i*(xf-x0)/(NUMX-1);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

hw7_solution - EME5 Homework 7 Solutions November 12, 2010...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online