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

  • SEARCH
  • Home
  • 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 6896547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:03:26+00:00 2026-05-27T07:03:26+00:00

I’m trying to write differential equation solver and i need to allow user to

  • 0

I’m trying to write differential equation solver and i need to allow user to input them by textbox. Problem is that solving method changes when equation contains only x or its something like x+y. Ifound great code on http://www.codeproject.com/KB/recipes/matheval.aspx but i have trouble on extending it into 2 methods

using System;
using System.Collections;
using System.Reflection;
namespace RKF45{
    public class MathExpressionParser
    {
        public object myobj = null;
        public ArrayList errorMessages;

        public MathExpressionParser()
        {
            errorMessages = new ArrayList();
        }
        public bool init(string expr)
        {
            Microsoft.CSharp.CSharpCodeProvider cp = new Microsoft.CSharp.CSharpCodeProvider();
            System.CodeDom.Compiler.CompilerParameters cpar = new System.CodeDom.Compiler.CompilerParameters();
            cpar.GenerateInMemory = true;
            cpar.GenerateExecutable = false;
            string src;
            cpar.ReferencedAssemblies.Add("system.dll");           
             src = "using System;" +
             "class myclass " +
             "{ " +
             "public myclass(){} " +

             "public static double eval(double x) " +
             "{ " +
             "return " + expr + "; " +
             "} " +

              "public static double eval2(double x,double y) " +
             "{ " +
             "return " + expr + "; " +
             "} " +

             "} ";
            System.CodeDom.Compiler.CompilerResults cr = cp.CompileAssemblyFromSource(cpar, src);
            foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
                errorMessages.Add(ce.ErrorText);

           if (cr.Errors.Count == 0 && cr.CompiledAssembly != null)
        {
            Type ObjType = cr.CompiledAssembly.GetType("myclass");
            try
            {
                if (ObjType != null)
                {
                    myobj = Activator.CreateInstance(ObjType);
                }
            }
            catch (Exception ex)
            {
                errorMessages.Add(ex.Message);
            }
            return true;
        }
        else
            return false;
    }

        public double eval(double x)
        {
            double val = 0.0;
            Object[] myParams = new Object[1] { x };
            if (myobj != null)
            {
                System.Reflection.MethodInfo evalMethod = myobj.GetType().GetMethod("eval");
                val = (double)evalMethod.Invoke(myobj, myParams);
            }
            return val;
        }
        public double eval2(double x, double y)
        {
            double val = 0.0;
            Object[] myParams = new Object[2] { x, y };
            if (myobj != null)
            {
                System.Reflection.MethodInfo evalMethod = myobj.GetType().GetMethod("eval2");
                val = (double)evalMethod.Invoke(myobj, myParams);
            }
            return val;
        }        
    }
}

Any ideas why eval2 method is not working correclty when i give expression like x+y ? eval is working fine but i need 2 of them to solve different equations inputted in textbox.

  • 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-05-27T07:03:27+00:00Added an answer on May 27, 2026 at 7:03 am

    You can’t use an expression containing two different variables (like “x” and “y”) both in eval(double x) and eval(double x, double y) method: the first one won’t compile (since the second variable is not defined there), whereas using expressions containing only single variable (like “x”) compiles in both cases. This explains why you can’t invoke eval2() in case of two variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
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’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.