Create Matrix of coefficients from nonlinear function
显示 更早的评论
This is the code im using. Based on question 3, I believe it is x^1, x^2, x^3, x^4 NOT x1 x2 x3 x4.
I attempted to use "[A]=equationsToMatrix(eqns)" but it states that it can not compute non linear equations.
syms x [4 1]
eqn1=16*x^1+32*x^2+33*x^3+13*x^4==91;
eqn2=5*x^1+11*x^2+10*x^3+x^4==16;
eqn3=9*x^1+7*x^2+6*x^3+12*x^4==5;
eqn4=34*x^1+14*x^2+15*x^3+x^4==43;
eqns=[eqn1;eqn2;eqn3;eqn4]

8 个评论
Torsten
2022-12-3
I can assure you that it is x = [x(1),x(2),x(3),x(4)], not x^1, x^2, x^3 and x^4.
John D'Errico
2022-12-3
编辑:John D'Errico
2022-12-3
You solve it by correctly writing the equations. The question did not tell you to raise x to those powers, but to solve for a vector of unknowns. Or you can write it to solve for the 4 unknowns x1, x2, x3, x4. Your choice. Then use solve. But your decision, to not believe the question was written correctly is simply wrong. It WAS written correctly. There are 4 unknown variables.
if so then how would I solve for x in the 3 question
This question has already been answered here:
The only thing missing in the answer is
x = A\b
Stephan
2022-12-3
Another way to solve for x would be the usage of linsolve. But A\b is what I would use too.
Benjamin
2022-12-3
The x in your assignment question is the vector x consisting of the four components x(1), x(2), x(3) and x(4).
I already wrote so, but you don't seem to read carefully.
And if you use the command
solve(eqns)
you can skip the line
[A,b]=equationsToMatrix(eqns)
because A and b are not used.
Stephan
2022-12-3
The question also is asking for the vector b which is 4x1 too. Why do you accept b as a vector but not x? Note that linear systems have the form A*x=b with A being a n*n matrix and b & x being vectors of size n*1.
回答(1 个)
I'm sorry, but you are most certainly incorrect.
A system of 4 equations like that would have 4 unknowns. In what you were shown, there are 4 unknowns listed. They are called x1,x2,x3,x4.
But it makes absolutely NO sense to have a system of 4 equations with ONE unknown, where the unknown is the same variable in all four equations. That is, suppose you wrote this as
syms x
eq1 = 16*x^1 + 32*x^2 + 33*x^3 + 13*x^4 == 91
As one polynomial equation, in one unknown, it has 4 roots. We can compute those roots easily enough, using solve. or vpasolve, for example.
vpasolve(eq1)
However, it makes no sense to pose a system of 4 polynomial equations like that, all with the SAME variable x. Each equation will have totally different roots, but no root in common. And there would not be any reason to call it a "system of equations" if your thinking about the equations was correct.
So I am sorry, but you are completely incorrect. There are 4 unknowns. Call them x1,x2,x3,x4. Call them x,y,z,w. Call them fred, barney, wilma, pebbles as you wish. But they ARE NOT powers. Yes, I know, you think it was a typo, and that you expected to see powers there. They are just 4 distinct variables.
And when you do write the problem in terms of 4 unknowns as I have suggested, now equationsToMatrix will work perfecly well.
类别
在 帮助中心 和 File Exchange 中查找有关 Linear Algebra 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
