codice:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using info.lundin.Math;
namespace MatematicaDerivate
{
public partial class Form1 : Form
{
//Variabili globali
String funz;
int scala;
double intersinistro;
double interdestro;
int passi;
double incremento;
double arrotondamento;
Point[] funzione = new Point[20000];
Point[] derivata = new Point[20000];
ExpressionParser parser = new ExpressionParser();
Hashtable h = new Hashtable();
//fine variabili globali
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)//disegno delle assi
{
Graphics g = e.Graphics;
Pen penna = new Pen(Color.Black);
penna.Width = 1.5F;
Pen onda = new Pen(Color.Purple);
Pen der = new Pen(Color.Olive);
for (int i = 1; i < pictureBox1.Width; i++)//asse x
{
g.DrawRectangle(penna, i, (pictureBox1.Height / 2), 0.1F, 0.1F);
}
for (int i = 1; i < pictureBox1.Height; i++)//asse y
{
g.DrawRectangle(penna, (pictureBox1.Width / 2), i, 0.1F, 0.1F);
}
g.DrawCurve(onda, funzione);
g.DrawCurve(onda, funzione);
}
private void button1_Click(object sender, EventArgs e)
{
scala=Convert.ToInt32(textBox7.Text);
funz = textBox1.Text;
intersinistro = Convert.ToDouble(textBox2.Text);
interdestro = Convert.ToDouble(textBox3.Text);
passi = Convert.ToInt32(textBox4.Text);
incremento = Convert.ToDouble(textBox5.Text);
arrotondamento = Convert.ToDouble(textBox6.Text);
for (int i = 1; i < 20000; i++)//genera la funzione normale
{
h.Add( "x", i.ToString() );
funzione[i - 1].X = (i*scala)-scala;
funzione[i - 1].Y = Convert.ToInt32((parser.Parse(funz, h)*scala)+(pictureBox1.Height/2));
h.Remove("x");
}
//programma del prof
double ps = (interdestro - intersinistro) / passi;
double x = intersinistro - ps;
int z=0;
while (x < interdestro + arrotondamento)//genera derivata
{
x = x + ps;
h.Add("x", (x + incremento).ToString());
double y2 = parser.Parse(funz, h);
h.Remove("x");
h.Add("x", (x - incremento).ToString());
double y1=parser.Parse(funz, h);
h.Remove("x");
double d=(y2-y1)/(2*incremento);
derivata[z].X=Convert.ToInt32((x*scala)-(pictureBox1.Width/2));
derivata[z].Y=Convert.ToInt32((d*scala)-(pictureBox1.Height/2));
z++;
}
//fine programma prof
pictureBox1.Refresh();
}
}
}
C'č qualcosa che non vā nella visualizzazione della derivata
questo č il programma originario del prof da convertire, c'č sicuramente qualche problema con la scala
codice:
10 'Programma per il calcolo delle derivate'
20 'Metodo semplice'
25 OPEN "C:\BBAS\ASU.PRN" FOR OUTPUT AS #3
30 DEF FNF(X)=SIN(X)
40 INPUT "INTERVALLO DI DERIVAZIONE X1,X2"; X1,X2
50 INPUT "NUMERO DI PASSi"; N
55 INPUT "INCREMENTO"; H
57 INPUT "ERRORE DI ARROTONDAMENTO"; P
60 PS=(X2-X1)/N
70 X=X1-PS
74 PRINT #3, "X DY/DX
80 WHILE X<X2+P
85 X=X+PS
90 Y1=FNF(X-H):Y2=FNF(X+H)
100 D=(Y2-Y1)/(2*H)
110 PRINT #3,X;D
112 WEND
113 CLOSE
114 END
aiutatemi... non trovo l'errore di scala
ecco cosa mi visualizza