Finding a scalar to make two arrays as equal as possible.

4 vues (au cours des 30 derniers jours)
Samuel Perrett
Samuel Perrett le 15 Fév 2020
Modifié(e) : Stephen23 le 15 Fév 2020
I have two arrays of the same size, I want to find a scalar which when you multiple the one array by the scalar (number) get's it as close to the other as pssible.
e.g. Two arrays A and B, scalar c.
A=cB
What would be the best way to code this, I was thinking either a fitting or just a for loop but I am unsure how to code it. I need to get the final value for c.
Thanksyou!

Réponses (1)

Stephen23
Stephen23 le 15 Fév 2020
Modifié(e) : Stephen23 le 15 Fév 2020
c = A(:) \ B(:)
For example:
>> A = rand(2,3);
>> B = A*0.23;
>> c = A(:) \ B(:)
c = 0.23000

Catégories

En savoir plus sur Linear Algebra dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by