How do I write an equation when I have both a variable and its value for one side
4 次查看(过去 30 天)
显示 更早的评论
Here's an example:
say we have
x=a+b+c;
y=ab;
z=c-a;
Three equations, three variables, easy. However, to get numerical answers, I'm gonna need numerical values for x,y,z, which will be user input. If for example, I know that x=5, how would I write that? x is already defined as a+b+c. can I just redefine it?
mind you later on, I will have other equations that will also involve x,y,z, which is why I'm hesitant to just use a function.
0 个评论
回答(1 个)
Doddy Kastanya
2021-1-6
The problem as you presented is non-linear and would need some manipulations before you can solve it. However, if "y=a+b" instead of "y=ab", then you can use MATLAB to find the values of a, b, and c, given the values of x, y, and z. You just need to write them in the following fashion, to put the known values on the right hand side:
a + b + c = x
a + b = y
-a + c = z
You have a coefficient matrix of [1 1 1; 1 1 0;-1 0 1] which is invertible. You can find the values of a, b, and c, by simply doing inv(coef matrix)*(x y z)'.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!