How to fit curve based on two related independent variables ?

Hello, I met this problem when doing curve fitting with 'fit' function, I wish get some help.
For independent variables, I have:
x=[1 2 3 4 5 6];
y=[1 1 1 2 2 2];
The dependent variable is:
z=[10 11 12 13 14 15];
My function is written as:
z=a*(x/y+x)
a is the coefficient to be evaluated. x and y varies but related, so x and y don't form a 2D plane. the result of 'x/y' in the function is actually supposed to be equivalent to 'x./y'.
I tried designating y as problem-depedent parameter (not working, as only one value is allowed for one parameter)
I tried using 'x./y' in the function, but it seems 'fit' still reads it as a 2D surface.
Please share your opinions on this problem, I have n't figure out the right way to do it yet. I appreciate a lot your help.
Sincerely
chen

Answers (1)

Ashok Kumar
Ashok Kumar on 11 May 2024
Edited: Ashok Kumar on 11 May 2024
The problem can be simplified defining a new variable w = x/y.
Doing so you will get
z = aw+ax
Now it is simplified for the linear fit.
find a for given a and w to get the best fit.
x = [1 2 3 4 5 6];
y = [1 1 1 2 2 2];
z = [10 11 12 13 14 15];
w = x ./ y; % To Compute w = x/y
% To build the design matrix
X = [w', x'];
a = X \ z';
disp(['Estimated value of a: ', num2str(a)]);

Categories

Asked:

on 5 Apr 2016

Edited:

on 11 May 2024

Community Treasure Hunt

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

Start Hunting!