Skip to content

Instantly share code, notes, and snippets.

Created September 27, 2014 12:57
Show Gist options
  • Select an option

  • Save anonymous/fc8ef6b198bcb8238f4c to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/fc8ef6b198bcb8238f4c to your computer and use it in GitHub Desktop.
void rk4()
{
label_t->Text = "t = " + t.ToString("F2");
label_x->Text = "x = " + x.ToString("F2");
label_y->Text = "y = " + fy(x).ToString("F2");
label_v->Text = "v = " + v.ToString("F2");
E = v*v*0.5 + fy(x);
label_E->Text = "E = " + E.ToString("F2");
t = t + dt;
x=xk;
v=vk;
k1x = dt*v;
k1v = dt*fv(x, v, t);
k2x = dt*(v + k1v / 2);
k2v = dt*fv(x + k1x / 2, v + k1v / 2, t + dt / 2);
k3x = dt*(v + k2v / 2);
k3v = dt*fv(x + k2x / 2, v + k2v / 2, t + dt / 2);
k4x = dt*(v + k3v);
k4v = dt*fv(x + k3x, v + k3v, t + dt);
xk = x + u * (k1x + 2 * k2x + 2 * k3x + k4x);
vk = v + u * (k1v + 2 * k2v + 2 * k3v + k4v);
pictureBox1->Invalidate();
pictureBox2->Invalidate();
pictureBox3->Invalidate();
}
private: System::Void pictureBox2_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e)
{
e->Graphics->DrawImage(bitmapa2, 0, 0);
Graphics^ grafika2 = Graphics::FromImage(bitmapa2);
Graphics^ grafika21 = e->Graphics;
System::Drawing::Font^ czcionka = gcnew System::Drawing::Font(System::Drawing::FontFamily::GenericSansSerif, 10, FontStyle::Regular);
// grafika2->Clear(Color::White);
Pen^ pen1 = gcnew Pen(Color::Gray);
Pen^ pen2 = gcnew Pen(Color::Black);
Pen^ pen3 = gcnew Pen(Color::Gray);
SolidBrush^ brush1 = gcnew SolidBrush(System::Drawing::Color::Red);
SolidBrush^ brush2 = gcnew SolidBrush(System::Drawing::Color::Gray);
// układ współrzędnych
pen1->Width = 2;
grafika2->DrawLine(pen1, eX2(Xp), eV(0.0), eX2(Xk), eV(0.0));
grafika2->DrawLine(pen1, eX2(0.0), eV(Vp), eX2(0.0), eV(Vk));
// trajektoria
pen2->Width = 1;
grafika2->DrawLine(pen2, eX2(x), eV(v), eX2(xk), eV(vk));
// siatka
pen3->Width = 0.5;
pen3->DashStyle = DashStyle::Dash;
for (int i = Vp; i<Vk + 1; i++)
grafika2->DrawLine(pen3, eX2(Xp), eV(i), eX2(Xk), eV(i));
for (int i = Xp; i<Xk + 1; i++)
grafika2->DrawLine(pen3, eX2(i), eV(Vp), eX2(i), eV(Vk));
// opis osi
for (int i = Xp; i<Xk; i++)
grafika2->DrawString(i.ToString(), czcionka, brush2, eX2(i), eV(0));
for (int i = Vp; i<Vk; i++)
grafika2->DrawString(i.ToString(), czcionka, brush2, eX2(0), eV(i));
// rysowanie bitmapy
e->Graphics->DrawImage(bitmapa2, 0, 0);
// kulka
grafika21->FillEllipse(brush1, eX2(x) - 4, eV(v) - 4, 8, 8);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment