我想使用数学克拉默定理做一个确定性计算器,正如你所看到的,我将该定理转化为代码convertedString = Convert.ToString (x * y1 * 1 + x1 * y2 * 1 + x2 * x * y - (1 * y1 * x2 + 1 * y2 * y + 1 * y * x1));
所有的好东西,直到我需要计算2个未知数的时候,我不知道如何在代码中告诉“x + x = 2x
”或“3y-y = 2y
”,所以我认为如果将Crammer方程转换为字符串,我可以找到所有匹配,如x + x
或y + 2y
或y * y
,并从该解决方案开始解决我的初始问题,就像我找到x * x
模式一样,我会通过if语句或者x * x
模式为x^2
的东西来告诉PC。 所以说,我想找出一些特定的序列,如X * y
或y + x
存在于一个字符串中,我尝试了一些foreach
循环和for
循环,但我不能让它工作,我不知道我应该如何接下来的问题,寻求帮助。我应该如何通过字符串搜索字符序列,如“x * y”?
这里是我的代码:
using System;
using InputMath;
namespace MathWizard
{
class Determinants
{
//Determinant of a first point and a second graphical point on the xoy axis.
public static void BasicDeterminant()
{
float x;
float y;
float x1 = Input.x1;
float y1 = Input.y1;
float x2 = Input.x2;
float y2 = Input.y2;
float result;
string convertedString;
string pointsValue;
string[] point;
Console.WriteLine("Please introduce the 2 graphical points (A and B) \n in the order x1 y1 x2 y2, separated by a space ");
pointsValue = Console.ReadLine();
point = pointsValue.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
x1 = Convert.ToInt32(point[0]);
y1 = Convert.ToInt32(point[1]);
x2 = Convert.ToInt32(point[2]);
y2 = Convert.ToInt32(point[3]);
//The Cramer's Rule for solving a 2 points determinant (P1(x1,y1) and P2(x2,y2)
convertedString = Convert.ToString (x * y1 * 1 + x1 * y2 * 1 + x2 * x * y - (1 * y1 * x2 + 1 * y2 * y + 1 * y * x1));
}
}
}
你声明'x1,x2,y1,y2'为'float',但是然后使用'Convert.ToInt16'从输入中获取它们。哪种类型是正确的? –
此代码不包含有关查找字符串的任何内容。你想达到什么目的? – PhilMasterG
您是否复制/粘贴其他人的代码,然后尝试修改它?这个不成立。 'x'和'y'总是'1',你也有一些硬编码的'1',全部用于乘法。 –