Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8683925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:10:01+00:00 2026-06-12T22:10:01+00:00

I’ve written or rather attempted to plot the free space Schrodinger equation in C#

  • 0

I’ve written or rather attempted to plot the free space Schrodinger equation in C# using ZedGraph and encountered a System.OutOfMemoryException error while running the created executable.

************** Exception Text **************
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Collections.Generic.List`1.set_Capacity(Int32 value)
   at System.Collections.Generic.List`1.EnsureCapacity(Int32 min)
   at System.Collections.Generic.List`1.Add(T item)
   at ZedGraph.PointPairList.Add(Double x, Double y)
   at Wavepacket.Form1.CreateGraph(ZedGraphControl schrodinger) in C:\Users\user1748005\Documents\Visual Studio 2010\Projects\Wavepacket\Wavepacket\Form1.cs:line 72
   at Wavepacket.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\user1748005\Documents\Visual Studio 2010\Projects\Wavepacket\Wavepacket\Form1.cs:line 35
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

The necessary functions/ constructors for my Cmplx class are relatively straightforward and are as such:

    public Cmplx(double r, double i)
    {
        this.real = r;
        this.imag = i;
    }

    public double Real
    {
        get { return this.real; }
        set { this.real = value; }
    }

    public double Imag
    {
        get { return this.imag; }
        set { this.imag = value; }
    }
    public Cmplx Multiply(Cmplx b)
    {
        return new Cmplx((this.real * b.real - this.imag * b.imag), (b.imag * this.real + this.imag * b.real));
    }

    public Cmplx Divide(Cmplx b)
    {
        return new Cmplx((this.real * b.real + this.imag * b.imag) / (b.real * b.real + b.imag * b.imag), (b.real * this.imag - this.real * b.imag) / (b.real * b.real + b.imag * b.imag));
    }

    public Cmplx Scale(Double b)
    {
        return new Cmplx(this.real * b, this.imag * b);
    }

    public double Mod()
    {
        return Math.Sqrt(this.real * this.real + this.imag * this.imag);
    }

    public Cmplx Sqrt()
    {
        double r, theta;
        r = this.Mod();
        theta = this.Arg();

        return new Cmplx(Math.Sqrt(r) * (Math.Cos(theta / 2)), Math.Sqrt(r) * Math.Sin(theta / 2));
    }

    public Cmplx Exp()
    {
        double x, y, z;
        x = Math.Exp(this.real);
        y = Math.Cos(this.imag);
        z = Math.Sin(this.imag);

        return new Cmplx(x * y, x * z);
    } 

Below are my ZedGraph methods with only the CreateGraph method modified from the Codeproject ZedGraph tutorial:

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Resize(object sender, EventArgs e)
    {
        SetSize();
    }

    private void SetSize()
    {
        zedGraphControl1.Location = new Point(10, 10);
        zedGraphControl1.Size = new Size(ClientRectangle.Width - 20,
                                ClientRectangle.Height - 20);
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        CreateGraph(zedGraphControl1);
        SetSize();
    }

    private void CreateGraph(ZedGraphControl schrodinger)
    {
        GraphPane myPane = schrodinger.GraphPane;

        myPane.Title.Text = "Free Space Schrodinger Equation)";
        myPane.XAxis.Title.Text = "Time (s)";
        myPane.YAxis.Title.Text = "Psi";

        double alpha, beta, norm, k0, t;
        double L,N;

        L = 25;
        N = 4096;
        alpha = 0.5;
        beta = 0.5785;  
        k0 = 1;
        t = 0;
        norm = (Math.Exp(-k0 * k0 * alpha)) * (Math.Pow((alpha / (2 * Math.PI)), 0.25));

        PointPairList list1 = new PointPairList();

        for (double i = -L; i <= L; i -= (-2L) / N)
        {
            Cmplx gamma = new Cmplx(alpha, beta * t);
            Cmplx a = new Cmplx(2 * alpha * k0, 0);
            a.Imag = i;
            Cmplx b = a.Multiply(a);
            Cmplx phi = (((b.Divide(gamma.Scale(4))).Exp()).Scale(norm)).Divide(gamma.Sqrt());
            list1.Add(phi.Mod(),i);
        }

        LineItem myCurve = myPane.AddCurve("t=0",
              list1, Color.Red, SymbolType.Default);
        schrodinger.AxisChange();
    }

I’ve changed the

list1.Add(phi.Mod(), i); 

line within the for loop of the above code block to a

Console.WriteLine("{0}, {1}", phi.Mod(), i); 

and this works as expected albeit within a command-line interface. The Windows Form Application using the ZedGraph library results consumes ~1.7GB of RAM before throwing the aforementioned exception.

I’ve found an instance where ZedGraph is running out of memory by plotting massive amounts of data points

Charting massive amounts of data

However I’m less inclined that my plot of a meagre 4096 data points would lead to such consumption of memory and would rather fault my (lack of) programming skills

NB: This is an academic assignment so any help provided should take that into account. Cheers!

EDIT: Fixed the initialization of L and N as ints rather than doubles. Problem still persists as aforementioned.

EDIT2 I am an idiot. I changed the initialization of L and N to doubles within my test CLI project but failed to update the source code of the Windows Form Application. Thanks to Jeppe Stig Nielsen for pointing me in the right direction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:10:02+00:00Added an answer on June 12, 2026 at 10:10 pm

    Check your for loop. It looks like there’s one minus (-) too many.

    Also, your division (-2*L) / N (an asterisk * missing) will give zero because it’s an integer division. To fix that, cast one factor to double, or simply write:

    2.0 * L / N
    

    Note that .0 denotes a floating-point number (System.Double), and this will force the whole computation of the “step” to be performed with floating-point as desired.

    To sum up: If your step is either zero, or goes in the wrong direction, you will keep adding points to list1 until you run out of memory. Maybe this for loop is better (but test it yourself):

    for (double i = -L; i <= L; i += (2.0 * L) / N)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.