Solving Matrix elements by using while iteration in Matlab
Show older comments
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)
Accepted Answer
More Answers (1)
John D'Errico
on 18 May 2017
Edited: John D'Errico
on 18 May 2017
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 Comments
doughnut nut
on 18 May 2017
John D'Errico
on 19 May 2017
Edited: John D'Errico
on 19 May 2017
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.
Categories
Find more on Code Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!