hw5_solution

hw5_solution - EME5 Homework 5 Solutions October 29, 2010 5...

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

View Full Document Right Arrow Icon
EME5 Homework 5 Solutions October 29, 2010 5 Chapter 6, Problem 6 5.1 Part b 5.1.1 Solution Code #include<stdio.h> #include<math.h> double g2(double x) { return x*x*sqrt(2*x); } int main() { double x = 3.5; double result; result = g2(x); printf("g2(3.5) = %f\n", result); return 0; } 5.1.2 Solution Output g2(3.5) = 32.410454 6 Chapter 6, Problem 7 6.1 Part b 6.1.1 Solution Code #include<stdio.h> #include<math.h> double g6(double x, double y) { 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
return x*x*sqrt(2*y); } int main() { double x = 3.5; double y = 4.2; double result; result = g6(x, y); printf("g6(3.5, 4.2) = %f\n", result); return 0; } 6.1.2 Solution Output g6(3.5, 4.2) = 35.503873 7 Chapter 6, Problem 8 7.1 Part b 7.1.1 Solution Code #include <stdio.h> #include <math.h> #include <chplot.h> #define NUM_POINTS 100 double f2(double x) { double retval; retval = x*x*sqrt(2*x); return retval; } int main() { double x, x0, xf, xstep, result; int i, n; printf(" x f2(x)\n"); printf(" ---------------\n"); x0 = -1.0; /* initial value for x */ xf = 5.0; /* final value for x */ xstep = 0.25; /* step size for x */ n = (xf - x0)/xstep + 1; /* number of points */ 2
Background image of page 2
for(i = 0; i < n; i++) { x = x0 + i*xstep; /* calculate value x */ result = f2(x); printf("%8.4f %8.4f\n", x, result); } fplotxy(f2, x0, xf, NUM_POINTS, "function f2(x)", "x", "y"); return 0; } 7.1.2 Solution Output x f2(x) --------------- -1.0000 nan -0.7500 nan -0.5000 nan -0.2500 nan 0.0000 0.0000 0.2500 0.0442 0.5000 0.2500 0.7500 0.6889 1.0000 1.4142 1.2500 2.4705 1.5000 3.8971 1.7500 5.7294 2.0000 8.0000 2.2500 10.7392 2.5000 13.9754 2.7500 17.7356 3.0000 22.0454 3.2500 26.9292 3.5000 32.4105 3.7500 38.5117 4.0000 45.2548 4.2500 52.6608 4.5000 60.7500 4.7500 69.5423 5.0000 79.0569 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
7.1.3 Solution Plot 8 Chapter 6, Problem 9 8.1 Part b 8.1.1 Solution Code #include <stdio.h> #include <math.h> #include <chplot.h> #define NUM_X_POINTS 100 #define NUM_Y_POINTS 100 double f6(double x, double y) { double retval; retval = x*x*sqrt(2*y); return retval; } int main() { double x, x0, xf, xstep, y, y0, yf, ystep, result; int i, j, nx, ny; printf(" x y f6(x,y)\n"); 4
Background image of page 4
printf(" -----------------------------\n"); x0 = -1.0; xf = 5.0; xstep = 1.0; nx = (xf - x0)/xstep + 1; /* num of points for x */ y0 = 2.0; yf = 4.0; ystep = 0.5; ny = (yf - y0)/ystep + 1; /* num of points for y */ for(i = 0; i < nx; i++) { x = x0 + i*xstep; /* calculate value for x */ for(j = 0; j <ny; j++) { y = y0 + j*ystep; /* calculate value for y */
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/23/2011 for the course EME 5 taught by Professor Staff during the Fall '08 term at UC Davis.

Page1 / 17

hw5_solution - EME5 Homework 5 Solutions October 29, 2010 5...

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

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