0% found this document useful (0 votes)
14 views4 pages

Program Integration Trapezoidal

The document discusses numerical integration using the trapezoidal rule. It shows code to calculate the trapezoidal rule for varying numbers of trapezoids and integrate an example function between x=1 and x=2. The document also contains code for a multi-step predictor method using 4 steps to solve a differential equation between 0 and 2.

Uploaded by

Gita Damayanti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Program Integration Trapezoidal

The document discusses numerical integration using the trapezoidal rule. It shows code to calculate the trapezoidal rule for varying numbers of trapezoids and integrate an example function between x=1 and x=2. The document also contains code for a multi-step predictor method using 4 steps to solve a differential equation between 0 and 2.

Uploaded by

Gita Damayanti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Program Integration Trapezoidal

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace TrapRule
{
class Program
{
//Quick Demo of Numerical integration
static void Main(string[] args)
{
//Show results for different numbers of trapezoids
for (int i = 3; i < 100; ++i)
Console.WriteLine(i.ToString() + ": " +
TrapezRule(x => x * x, 1, 2, i));
//Change x * x above to numerically integrate
//a different function than f(x) = x^2
//Above integrates between x=1 and x=2
if (Debugger.IsAttached)
Console.ReadKey();
}

static double TrapezRule(Func<double, double> func, double a, double b, int n)


{
double area = 0;
double w = (b - a) / n;
area += (func(a) + func(b)) / 2;
for (int p = 1; p < n; ++p)
area += func(a + w * p);
return w * area;
}
}
Program Multi Step Predictor, n=4

#include<stdio.h>
#include<math.h>
#include<iostream>

#define true 1
#define false 0
#define MAX_N 2000

static double F(double, double);

using namespace std;

int main()
{
double A, B, ALPHA, H, T, W[MAX_N], K1, K2, K3, K4;
int I, N;

A = 0.0;
B = 2.0;
N = 10;

cout.setf(ios::fixed, ios::floatfield);
cout.precision(10);

H = (B - A) / N;
T = A;
W[0] = 0.5; // initial value
K1 = H * F(T, W[I - 1]);
K2 = H * F(T + H / 2.0, W[I - 1] + K1 / 2.0);
K3 = H * F(T + H / 2.0, W[I - 1] + K2 / 2.0);
K4 = H * F(T + H, W[I - 1] + K3);
W[I] = W[I - 1] + 1 / 6.0 * (K1 + 2.0 * K2 + 2.0 * K3 + K4);
cout << "At time " << T << " the solution = " << W[I] << endl;
for (I = 4; I <= N; I++)
{
K1 = 55.0 * F(T, W[I - 1]) - 59.0 * F(T - H, W[I - 2]) + 37.0 * F(T - 2.0 * H, W[I - 3]) - 9.0 * F(T - 3.0 *
H, W[I - 4]);
W[I] = W[I - 1] + H / 24.0 * K1;

/* COMPUTE T(I) */
T = A + I * H;

cout << "At time " << T << " the solution = " << W[I] << endl;
}

return 0;
Program Polygon

MsSql2008GeometryReader geometryReader = new MsSql2008GeometryReader();


MsSql2008GeometryWriter geometryWriter = new MsSql2008GeometryWriter();
using (SqlConnection con = new SqlConnection(@"Data Source=localhost;Initial Catalog=Northwind;
Integrated Security=True"))
{
con.Open();
using (SqlCommand command = new SqlCommand("SELECT * FROM MY_SPATIAL_TABLE", con))
using (SqlDataReader dataReader = command.ExecuteReader())
{
while (dataReader.Read())
{
IGeometry geom = geometryReader.Read((byte[])dataReader["my_geometry_field"]);
geom.Coordinates[0].X = 1;
geom.Coordinates[0].Y = 1;

byte[] outputMsSqlGeom = geometryWriter.Write(geom);


}
}
}
TUGAS KELOMPOK
DASAR KOMPUTER I

Ketua:

- Indra Rizal A

Anggota:

- Kodar Komarudin
- Wafa Nadia
- Rezki Vila Patra
- Chika Khoerunnisa

TEKNIK KIMIA
INSTITUT TEKNOLOGI NASIONAL
BANDUNG
2017

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy