MATLAB Answers

0

simultaneous fitting of two plots with two functions

Asked by Arun Kumar Bar on 16 Sep 2018 at 21:03
Latest activity Commented on by Torsten
on 17 Sep 2018 at 11:25

I have two sets of dependent variable column vectors (y1, y2) for a set of independent variable column vectors (x). I want to fit the (x, y1) plot with the function f1(ca. f1 = (a + (b-a)*(1 + c*x^d))) and the (x, y2) plot with the function f2(ca. f2 = (b-a)*c*x^d)) simultaneously. Could anyone please help?

Many thanks, in advance! Arun

  2 Comments

What do you mean by simultaneous? Based on your equations, the transformation from x to y_1 is independent of y_2 and likewise x -> y_2 is independent of y_1. So you can just fit the two functions separately.

The parameters a, b, c and d are to be same for both the fits. If I fit separately, it will not guarantee same values of the parameters for both the fits. Anyway, thank you.

Sign in to comment.

Products


Release

R2018a

2 Answers

Answer by Torsten
on 17 Sep 2018 at 9:49
 Accepted Answer

Use "lsqcurvefit" with the data set xdata = (x,x),ydata = (y1,y2).

Best wishes

Torsten.

  2 Comments

Hi Torsten, In fact I new that lsqcurvefit would work. But when I do it, it ends with an error: the function values and the ydata are not of same size. Most probably I am messing with the function set-up.

I was trying as follow:

xdata=[x(:1); x(:1)];

ydata=[y1(:1); y2(:1)]; % FYI, all x(:1), y1(:1) and y2(:1) are of same size.

fun=@(x,xdata) f1(x,a,b,c,d); f2(x,a,b,c,d);

x0=[- - - -];

x=lsqcurvefit(fun,xO,xdata, ydata);

Though I am not able to find out, I am definitely making a mess somewhere. Could you please point out?

Thanks and regards, Arun

xdata=[x(:,1); x(:,1)];
ydata=[y1(:,1); y2(:,1)]; 
fun=@(x,xdata) [f1(xdata(1:numel(xdata)/2),x(1),x(2),x(3),x(4)); f2(xdata(1:numel(xdata)/2),x(1),x(2),x(3),x(4))];
x0=[- - - -];
x=lsqcurvefit(fun,x0,xdata,ydata);

where f1(...),f2(...) must be column vectors each of the same size as xdata(1:numel(xdata)/2).

Best wishes

Torsten.

Sign in to comment.


Answer by Torsten
on 17 Sep 2018 at 11:23

xdata=[x(:,1); x(:,1)];
ydata=[y1(:,1); y2(:,1)]; 
fun=@(x,xdata) [f1(xdata(1:numel(xdata)/2),x(1),x(2),x(3),x(4)); f2(xdata(1:numel(xdata)/2),x(1),x(2),x(3),x(4))];
x0=[- - - -];
x=lsqcurvefit(fun,x0,xdata,ydata);

where f1(...),f2(...) must be column vectors each of the same size as x.

  0 Comments

Sign in to comment.