optimization for minimum difference between 2 graphs

2 views (last 30 days)
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.

Answers (1)

ag
ag on 7 Feb 2025
Edited: ag on 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!

Categories

Find more on Graph and Network Algorithms 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!