##ReadMore##
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace examination_2
{
public partial class exam2 : Form
{
Stopwatch stopWatch = new Stopwatch();
public exam2()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
// Start Watch
stopWatch.Reset();
stopWatch.Start();
// Integration
int steps = 10000;
double ans = 0;
double x, fx;
double en = 4 * Math.PI;
double bn = 0;
double parti = (en - bn) * 1 / steps;
for (int i = 0; i < steps; i++)
{
x = bn + parti * i;
fx = x * x * x * Math.Sin(2 * x) * Math.Cos(x);
ans = ans + fx * parti;
}
// Stop Watch
stopWatch.Stop();
// Show timesapn and Answer
TimeSpan ts = stopWatch.Elapsed;
textBox1.Text = ts.ToString();
textBox2.Text = ans.ToString();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
}
}
沒有留言:
張貼留言