This project is read-only.

graph the ODE's solution

Apr 3, 2011 at 12:14 PM

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Research.DynamicDataDisplay;
using Microsoft.Research.DynamicDataDisplay.DataSources;
using Microsoft.Research.DynamicDataDisplay.PointMarkers;
using Microsoft.Research.DynamicDataDisplay.Charts;
using Microsoft.Research.DynamicDataDisplay.ViewportRestrictions;

namespace WpfApplication7
{
    public class SampleMarker : ShapeElementPointMarker
    {
        public override UIElement CreateMarker()
        {
            Canvas result = new Canvas()
            {
                Width = 10,
                Height = Size
            };
            result.Width = Size;
            result.Height = Size;
            result.Background = Brush;
            if (ToolTipText != String.Empty)
            {
                ToolTip tt = new ToolTip();
                tt.Content = ToolTipText;
                result.ToolTip = tt;
            }
            return result;
        }

        public override void SetPosition(UIElement marker, Point screenPoint)
        {
            Canvas.SetLeft(marker, screenPoint.X - Size / 2);
            Canvas.SetTop(marker, screenPoint.Y - Size / 2);
        }
    }
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public delegate double Function(double t, double y);
        static double f(double t, double y)
        { return -2 * t * y + 2 * t * t * t * y * y * y; }
        const long b = 1000000;
        public MainWindow()
        {
         
            InitializeComponent();

        }

      //  public delegate double DoI (double q, double w);
     
        private static void DoIt(double q, double w)
        {
            MainWindow f1 = new MainWindow();

            double [] x = new double[b];
            x[0] = q;
            double[] y = new double[b];
            y[0] = w;

            var yDataSource = new EnumerableDataSource<double>(y);
            yDataSource.SetYMapping(Y => Y);
            yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty,
                Y => string.Format("Value is {0}", Y));

            var xDataSource = new EnumerableDataSource<double>(x);
            xDataSource.SetXMapping(X => X);

            CompositeDataSource compositeDataSource = new CompositeDataSource(xDataSource, yDataSource);

           


            f1.plotter.Viewport.Restrictions.Add(new PhysicalProportionsRestriction { ProportionRatio = 1 });

            // adding graph to plotter
            f1.plotter.AddLineGraph(compositeDataSource, new Pen(Brushes.Goldenrod, 3), new SampleMarker(), new PenDescription("Cosine"));
        }
       
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
          
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            Eiler_ODE a=new Eiler_ODE();
            a.Eiler(f,0,1,1,10,0.01);
        }

        public class Eiler_ODE
        {
           
                double[] x = new double[b];
                double[] y = new double[b];
                double Hy, Hz, Xy, Xz, y1, z;
                int i, j, k = 0;
                double[] sh = new double[b];
                double[] resh = new double[b];
                double[,] Ry = new double[2, b];
                double[,] Rz = new double[2, b];
           
            public void Eiler(Function f, double t0, double T, double y0, int n, double eps)
            {
               

                Hy=2*(T - t0) / n;
                Hz = (T - t0) / n;
                n = n / 2;
                do
                {
                    j = -1; n = 2 * n;
                    Hy = Hy / 2; Hz = Hz / 2;
                    Xy = Xz = t0;
                    y1 = z = y0;
                    for (i = 0; i <= n; i++)
                    {
                        j++;
                        Ry[0, i] = Xy;
                        Ry[1, i] = y1;
                        if (i < n)
                        {
                            double c = f(Xy, y1);
                            y1 = y1 + Hy * c;
                            Xy = Xy + Hy;
                        }
                        int D = j + 1;
                        for (j = D - 1; j <= D; j++)
                        {
                            Rz[0, j] = Xz; Rz[1, j] = z;
                            if (j < 2 * n)
                            {
                                z = z + Hz * f(Xz, y1);
                                Xz = Xz + Hz;
                            }

                        }
                        j--;


                    }
                    sh[k] = Math.Log(Hy);
                    resh[k] = Rz[1, 2 * n];
                    k++;

                }
                while (Math.Abs(Rz[1, 2 * n] - Ry[1, n]) > eps);

                MainWindow f1 = new MainWindow();

                for (j = 0; j < 2 * n; j++)
                {
                  //  x[j] = Rz[0, j];

                   // y[j] = Rz[1, j];

                    x[j] = j * 0.1;
                    y[j] = Math.Cos(x[j]);

                    DoIt(x[j],y[j]);

                }
            }
        }
    }
}

help me, please. This is very important for me.

Why the schedule isn't drawn?

(VS ошибок не выдает,но график почему-то не рисуется.. а как выводить несколько независимых графиков?)