如何在C#中求解方程

编程入门 行业动态 更新时间:2024-10-11 11:18:46
本文介绍了如何在C#中求解方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嗨 我想在asp c#中求解一个方程式 等式是

Hi I want to solve an equation in asp 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#中求解方程

本文发布于:2023-11-29 18:41:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647275.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方程   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!