practical04_sol - Practical Session 4 Solutions Exercises...

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

View Full Document Right Arrow Icon
Practical Session 4 — Solutions Exercises 1. (a) The value of the integral is I = 1 . (b),(c) A suitable code is the following, which produces the exact result. I’ll put this code on the web pages for reference. / * trap_line.c * Example code to integrate the function f(x)=x+1/2 defined by * the arrays x[N], f[N], using the trapezoidal rule. * / #include <stdio.h> #define N 10 float trapzd(float x[], float f[], int n); int main() { int i; float x[N], f[N], integral; / * define x[], f[] * / for (i = 0; i < N; i++) { x[i] = 1.0 * i/(N - 1.0); f[i] = x[i] + 0.5; } integral = trapzd(x, f, N); printf("Estimate of integral = %f\n", integral); return 0; } float trapzd(float x[], float f[], int n) { / * apply trapezoidal rule to integrate f[n] defined on x[n] * / float integral, dx; int i; integral = 0.0; for (i = 0; i < n - 1; i++) { dx = x[i + 1] - x[i]; integral += 0.5 * dx * (f[i] + f[i+1]); } return integral; } 2. (1002) (a) The plot is Figure 1. The sections of the spacecraft were jettisoned at about 163 s and 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
537 s according to the flight report. From the graph you can guess that the events were between 150 s and 175 s, and between 525 s and 550 s. 0
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 / 5

practical04_sol - Practical Session 4 Solutions Exercises...

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