optimization for minimum difference between 2 graphs

1 Ansicht (letzte 30 Tage)
Kinda Chakas
Kinda Chakas am 8 Aug. 2020
Bearbeitet: ag am 7 Feb. 2025
I have two graphs: graph 1 and grph 2
I want to find a,b such that: normalized graph1=graph 1 * a+b.
a and b should be chosen to give the minimum difference between normalized graph 1 and graph 2.
Thank you in advance for your help.

Antworten (1)

ag
ag am 7 Feb. 2025
Bearbeitet: ag am 7 Feb. 2025
Hi Kinda,
To find the optimal values of ( a ) and ( b ) such that the normalized version of graph 1 (i.e., graph1 * a + b) minimizes the difference with graph 2, you can use a least squares approach. This is essentially a linear regression problem where you aim to fit graph1 to graph2.
Below is a basic illustration of how you can achieve it:
graph1 = [1 2 0; 0 4 3]; % Your graph 1 data
graph2 = [8;18]; % Your graph 2 data
% Set up the design matrix for linear regression
X = [graph1, ones(size(graph1))];
% Solve the linear regression problem using the backslash operator
coefficients = X \ graph2;
% Extract the coefficients a and b
a = coefficients(1);
b = coefficients(2);
% Calculate the normalized graph1
normalized_graph1 = graph1 * a + b;
Please ensure to modify the code as per your requirements.
For more details, please refer to the following MathWorks documentation:
Hope this helps!

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by