如何用C编写程序来对包含2个变量的代数表达式进行操作? [英] How to write a program in C to do operations on algebraic expression containing 2 variables?
问题描述
如何在C中添加或减去2个具有2个变量的代数表达式。我意识到它可以使用矩阵完成,但会留下许多空格。任何人都可以写一个动态分配数组的程序。如何处理稀疏矩阵(数组表示)
示例问题:
P1(x,y)= 5x ^ 2y + 9x ^ 3y ^ 2
P2(x,y)= 9x ^ 3y ^ 2 + 12y ^ 2 + 10x ^ 4
我尝试过:
我试图通常在C中使用矩阵但我的教授放弃它,因为它创造了太多不必要的内存
抱歉,我们不会为您做功课。
您不需要使用矩阵。只需使用一组结构,每个结构包含:
并对类似功率组合的系数求和。
- 系数
- x的功率
- y的力量
/ ravi
How can I add or subtract 2 Algebraic expressions in C which have 2 variables. I realize it could be done using matrix but that would leave many null spaces. Can anyone please write a program dynamically allocating the arrays. How can I do with sparse matrix (array representation)
Example question:
P1(x,y) = 5x^2y + 9x^3y^2
P2(x,y) = 9x^3y^2 + 12y^2 + 10x^4
What I have tried:
I have tried to do it normally using matrix in C but my professor discarded it as it was creating too much unnecessary memory
Sorry, we do not do your homework for you.
You don't need to use a matrix. Simply use a collection of structures, each of which contains:
and sum the coefficients of like power combinations.
- coefficient
- power of x
- power of y
/ravi
这篇关于如何用C编写程序来对包含2个变量的代数表达式进行操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!