Solving Matrix elements by using while iteration in Matlab
이전 댓글 표시
I have a known 5X6 sized M matrix, and a 6x1 sized K matrix which its 4 elements unknowns and two knowns. P matrix obtained by multiplication of these two matrices and has different 5 elements all which function of an x variable. Altogether, there are 5 equations and 5 unknowns (four from the K, and one from the P(which is x))
How can I obtain a while iteration in Matlab to solve these 5 unknowns? Is this possible in Matlab with the while or for loop? `
M[5X6]*K[6X1]=P[5X1]
P=[constant*x, constant2*x, constant3*x, constant4*x, constant5*x)
채택된 답변
추가 답변 (1개)
John D'Errico
2017년 5월 18일
편집: John D'Errico
2017년 5월 18일
Please stop asking the same question over and over again.
NO you cannot solve it using a while or for loop.
P = sym('P',[6 1])
syms x
M = rand(5,6);
P(1) = rand(1);
P(6) = rand(1);
rhs = rand(5,1)*x;
result = solve(M*P == rhs)
result =
struct with fields:
P2: [1×1 sym]
P3: [1×1 sym]
P4: [1×1 sym]
P5: [1×1 sym]
x: [1×1 sym]
vpa(result.P2)
ans =
-0.18252717543791916818862612728557
...
vpa(result.x)
ans =
-0.096463182153227195863683959815006
Now please stop asking if this can be solved using a while loop.
(Yes, in fact, you could have put a while loop in there that does absolutely nothing. Will that make you happier?)
댓글 수: 2
doughnut nut
2017년 5월 18일
John D'Errico
2017년 5월 19일
편집: John D'Errico
2017년 5월 19일
Yes, you COULD come up with some iterative scheme that would solve the problem using a while loop. But why would you bother? I just showed you how to solve the problem, but there was NO while loop needed. In fact, there is no conceivable reason why you would want to use a while loop here when one is not needed.
For some reason, it seems you think this problem needs a while loop. If someone told you to use a while loop, they simply did not know what they were talking about.
카테고리
도움말 센터 및 File Exchange에서 Code Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!