如何在C#中求解方程 [英] How to solve equations in c#
问题描述
嗨
我想在asp.net c#中求解一个方程式
等式是
Hi
I want to solve an equation in asp.net c#
Equation is
int x0 = 5;
int x1 = 2;
然后
then
y = (x-x0)/(x0-x1)
它应该像
一样返回
it should return like
y = (x-5)/3;
但是
它显示了x不确定的错误....
请帮我解决这个问题.
致以问候
在此先感谢
Manju K
But
It shows an error like x is undefined....
Please help me in solving this.
With Regards
Thanks in Advance
Manju K
推荐答案
请查看该站点,它可能对您有帮助,
将数学方程式转换为C# [
Please have a look this site which might help you,
Converting math equations to C#[^]
:)
我看不到您已经声明了变量x,y
这样编译器就会抛出该错误
要解决该错误,您可以在函数中声明x,y变量,例如:
i don''t see you have been declare variable x, y
so that the compiler throws that error
to solve that error, you can declare x, y variable inside your function like:
int x = 100; // value 100 is an example
int y = 100; // value 100 is an example
int x0 = 5;
int x1 = 2;
....
或编写如下函数:
....
or write an function like:
public int MyEquation(int x)
{
int y;
// here is your code
return y;
}
您需要在这里告诉我们您要实现的目标.使用给定的信息,可以很容易地通过String.Format完成此操作.但这对您有帮助吗?我认为不会.
You need to tell us what exactly you are trying to acheieve here. With the given information, this can be very easily done through String.Format. But does it help you? I think it will not.
int x0 = 5;
int x1 = 3;
string originalString = "y = (x-{0})/({1})";
string updatedString = string.Format(originalString, x0, (x0 - x1));
您需要实现自己的解析器,以解决方程式.需要充分了解您的要求以帮助您.在Google中搜索"C#Equation Parser".它可能会给您一些思路.
You need to implement a parser of your own which could solve the equations. One needs to be well aware of your requirements to help you out. Search google for "C# Equation Parser". It may give you some ideas to start with.
这篇关于如何在C#中求解方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!