Minimizing an equation to 0
Show older comments
I have an equation where I am trying to reduce the RMS to 0 i.e RMS(A-(B+C)<=0. A,B and C are known but the RMS is not equal to 0 . Now, I want to modify this equation such that RMS(A-(k1*B+k2*C)<=0. I want to find k1 and k2 to make the RMS as close to 0. How could I do this?
2 Comments
Walter Roberson
on 11 Sep 2022
are A, B, C matrices? Are k1 and k2 scalar?
AAS
on 11 Sep 2022
Answers (3)
A = [4 3; 6 2; 7 -3];
B = [1 -3; 2 2; 5 -pi];
C = [12 -0.5; 7 -3; 0 1];
fun = @(p)reshape(A-(p(1)*B+p(2)*C),[],1);
sol = lsqnonlin(fun,[1 1])
error = rms(fun(sol))
Bruno Luong
on 11 Sep 2022
Edited: Bruno Luong
on 11 Sep 2022
This minimize the frobenius norm, or l2 norm of the vectorized residual matrix (divided by sqrt(numel(A)) you'll get the rms)
k=[B(:),C(:)]\A(:);
k1=k(1);
k2=k(2);
Categories
Find more on Correlation and Convolution 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!