fitting 3 sets of data simultaneously using "lsqcurvefit"

I have a set of data in triplicates (attached). I want to fit the exponential part of these 3 sets simultaneously using "lsqcurvefit" and get one x(1) and x(2). I have included "t" and "or" data in the attached file and here is my function:
function y=or(x,t)
y=((0.282*x(2))-0.24)*x(1)*exp((x(2)-0.24)*t)
I managed to fit each data set individually and average x(1) and x(2) and calculte the STdev but if I could fit 3 sets simultenausly using "lsqcurvefit" would be better.
I would be grateful if you kindly help me.

Antworten (2)

Torsten
Torsten am 18 Mai 2022
Define
T = [t1;t2;t3]
and
OR = [or1;or2;o3]
and treat
[T,OR]
just like you treated
[t1;or1],[t2;or2],[t3;or3]
.
What's the problem ?

9 Kommentare

Sara
Sara am 18 Mai 2022
Bearbeitet: Sara am 18 Mai 2022
I have one t, it is the same for or1, or2, and or3. I have defined the fit as below for each or:
rangemin = 173;
rangemax = 212;
xprime(1)=100;
xprime(2)=7;
[x(1,:)]=lsqcurvefit(@or,xprime,t(rangemin:rangemax),ordata(rangemin:rangemax,1));
[x(2,:)]=lsqcurvefit(@or,xprime,t(rangemin:rangemax),ordata(rangemin:rangemax,2));
[x(3,:)]=lsqcurvefit(@or,xprime,t(rangemin:rangemax),ordata(rangemin:rangemax,3));
y(:,1)=or(x(1,:),t);
y(:,2)=or(x(2,:),t);
y(:,3)=or(x(3,:),t);
function y=or(x,t)
y=((0.282*x(2))-0.24)*x(1)*exp((x(2)-0.24)*t);
end
…………………………………………………….
I am new in Matlab and it took me a long time to do this.
Do you mean that I write as:
[x(1,:), x(2,:), x(3,:)]=lsqcurvefit(@or(x(1,:),t);or(x(2,:),t);or(x(3,:),t),xprime,t(rangemin:rangemax),ordata(rangemin:rangemax,1,2,3));
Matt J
Matt J am 18 Mai 2022
Bearbeitet: Matt J am 18 Mai 2022
Do not name your model function or(). It conflicts with the name of a (very important) built-in Matlab function.
x=lsqcurvefit(@modelfun,xprime,t,[OR1(:),OR2(:),OR3(:)])
function y=modelfun(x,t)
y=((0.282*x(2))-0.24)*x(1)*exp((x(2)-0.24)*t(:));
y=[y,y,y];
end
I have x(1) and x(2), I wrote as below but it doesnt work:(
[x(1,:)]=lsqcurvefit(@modelfun,xprime,t(rangemin:rangemax),or(rangemin:rangemax,:));
y(:,1)=[modelfun(x(1,:);modelfun(x(2,:);modelfun(x(3,:),t)];
figure
plot(t,or(:,1),t(rangemin:rangemax),y(rangemin:rangemax),'o');
function modelfun(x,t)
y=((0.282*x(2))-0.24)*x(1)*exp((x(2)-0.24)*t(:));
y=[y,y,y];
end
[x(1,:)]=lsqcurvefit(@modelfun,xprime,t(rangemin:rangemax),ordata(rangemin:rangemax,:)); % watch 3rd argument
Use the 3rd argument to function as ordata instead of or and try
Torsten
Torsten am 19 Mai 2022
Bearbeitet: Torsten am 19 Mai 2022
rangemin = 173;
rangemax = 212;
xprime(1)=100;
xprime(2)=7;
TDATA = [t(rangemin:rangemax).';t(rangemin:rangemax).';t(rangemin:rangemax).'];
ORDATA = [ordata(rangemin:rangemax,1);ordata(rangemin:rangemax,2);ordata(rangemin:rangemax,3)];
x = lsqcurvefit(@modelfun,xprime,TDATA,ORDATA);
Y = modelfun(x,TDATA)
Y = reshape(Y,numel(t(tangemin:rangemax)),3);
function modelfun(x,t)
y=((0.282*x(2))-0.24)*x(1)*exp((x(2)-0.24)*t);
end
Sara
Sara am 19 Mai 2022
Bearbeitet: Sara am 19 Mai 2022
Thanks very much but gives error in
TDATA = [t(rangemin:rangemax).';t(rangemin:rangemax).';t(rangemin:rangemax ).'];
Is t a row or a column vector ?
If it is a column vector, use
TDATA = [t(rangemin:rangemax);t(rangemin:rangemax);t(rangemin:rangemax)];
column, it worked but now gives error on
Y1 = Y(1:numel(t(trangemin:rangemax)));
Torsten
Torsten am 19 Mai 2022
Bearbeitet: Torsten am 19 Mai 2022
Y is a numel(t(tangemin:rangemax)) x 3 - matrix.
So
Y1 = Y(:,1)
Y2 = Y(:,2)
Y3 = Y(:,3)
guessing you used the code I submitted.

Melden Sie sich an, um zu kommentieren.

Sara
Sara am 19 Mai 2022

0 Stimmen

ok, sorry many comments so was confused:(
I think this is based on your comment:
rangemin = 173;
rangemax = 212;
xprime(1)=100;
xprime(2)=7;
TDATA = [t(rangemin:rangemax);t(rangemin:rangemax);t(rangemin:rangemax)];
ORDATA = [ordata(rangemin:rangemax,1);ordata(rangemin:rangemax,2);ordata(rangemin:rangemax,3)];
x = lsqcurvefit(@or,xprime,TDATA,ORDATA);
Y = or(x,TDATA);
Y = reshape(Y,numel(t(tangemin:rangemax)),3);
function y=or(x,t)
y=((0.282*x(2))-0.24)*x(1)*exp((x(2)-0.24)*t);
end
but still gives error on Y = reshape(Y,numel(t(tangemin:rangemax)),3);

3 Kommentare

Torsten
Torsten am 19 Mai 2022
Bearbeitet: Torsten am 19 Mai 2022
Y = reshape(Y,numel(t(rangemin:rangemax)),3);
instead of
Y = reshape(Y,numel(t(tangemin:rangemax)),3);
My fault, sorry.
these seem the same?
rangemin vs. tangemin ?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Third-Party Cluster Configuration finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2022a

Gefragt:

am 18 Mai 2022

Kommentiert:

am 19 Mai 2022

Community Treasure Hunt

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

Start Hunting!

Translated by