How can I solve an equation in a While loop?
2 次查看(过去 30 天)
显示 更早的评论
Hi. I have a equation like below.
[m1 m2 ; m3 m4] * [d1 ; d2] = [c1 ; c2]
The values of m1, m2, m3, m4 and c1, c2 change in a while loop.
I want to find the d1 and d2 values in every Iteration of the mentioned while loop.
I wrote this, but some times it return Nan values.
[d1 ; d2] = [m1 m2 ; m3 m4] \ [c1 ; c2];
How can I do that?
Thanks a lot.
0 个评论
回答(2 个)
Walter Roberson
2018-4-12
That equation does not always have solutions. Your m might be singular or the calculation might overflow or might contain inf in ways lead to nan.
If you have the symbolic toolbox sometimes you can get further by putting sym() around the two sides of the \ operator, but if that helps you probably need to go back and do the calculation of the m and c values as sym.
3 个评论
Walter Roberson
2018-4-16
Please follow the debugging instructions I indicated with dbstop and so on.
Torsten
2018-4-12
Maybe m1, m2, m3, m4, c1, c2 are NaN ?
And use
D = [m1 m2 ; m3 m4] \ [c1 ; c2];
d1 = D(1);
d2 = D(2);
And always make sure that det(M) does not equal 0 before computing D.
Best wishes
Torsten.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!