how to make non linear model fitting ?

it is a paper drying experiment actually i have an experimental measurement of the following for 100% power which is 700W the weight of paper is changes as follows through time W=[4g 2.7g 1.4g 0.9g] in time of t=[0second 15second 30second 60second] for 90% power which is 630W the weight of paper is changes as follows through time W=[4 3 1.4 1.2];t=[0second 15second 45second 90second]; for 80% power which is 560W the weight of paper is changes as follows through time W=[4g 3g 2.7g 2g ] ;t=[0second 15second 30second 60second] having this datas i want to get a model of W=a*p*exp(-b*p*t) where t and p are the independent time and power variables and the a and b are constant coefficients to be determined from the non linear fitting. so can any one help how to do it please ?

1 Comment

If you have the curve fitting toolbox, you can use the fit function with a custom equation.

Sign in to comment.

 Accepted Answer

Try this:
W = [4.0 2.7 1.4 0.9; 4.0 3.0 1.4 1.2; 4.0 3.0 2.7 2.0];
T = [ 0 15 30 60; 0 15 45 90; 0 15 30 60; ];
P = [700; 630; 560];
PT = [reshape(repmat(P',size(W,2),1),1,[])' reshape(T',[],1)]; % Create ‘PT’ Matrix
Wv = reshape(W', [],1); % Create ‘W’ Vector
Wfcn = @(x,pt) x(1).*pt(:,1).*exp(-x(2).*pt(:,1).*pt(:,2)); % Objecive Function
B1 = fminsearch(@(x) norm(Wv - Wfcn(x,PT)), [0.001; 0.1]); % Estimate Parameters For All Data
cm = [1 0 0; 0 1 0; 0 0 1]; % RGB Colormap
figure(1)
AxH1 = axes('NextPlot','add');
for k1 = 1:size(W,1)
% Q = PT(1+4*(k1-1):4+4*(k1-1),:)
hp1(k1) = plot(AxH1,T(k1,:), W(k1,:), 'p', 'MarkerEdgeColor',cm(k1,:), 'MarkerFaceColor',cm(k1,:), 'DisplayName',sprintf('%d W',P(k1)));
plot(AxH1,T(k1,:), Wfcn(B1,PT(1+4*(k1-1):4+4*(k1-1),:)), '-', 'Color',cm(k1,:))
end
grid
legend(hp1)
hold off
figure(2)
AxH2 = axes('NextPlot','add');
for k1 = 1:size(W,1)
B2(:,k1) = fminsearch(@(x) norm(Wv(1+4*(k1-1):4+4*(k1-1),:) - Wfcn(x,PT(1+4*(k1-1):4+4*(k1-1),:))), [0.001; 0.1]); % Estimate Parameters For Each Power
hp2(k1) = plot(AxH2, T(k1,:), W(k1,:), 'p', 'MarkerEdgeColor',cm(k1,:), 'MarkerFaceColor',cm(k1,:), 'DisplayName',sprintf('%d W',P(k1)));
plot(AxH2, T(k1,:), Wfcn(B2(:,k1),PT(1+4*(k1-1):4+4*(k1-1),:)), '-', 'Color',cm(k1,:))
end
grid
legend(hp2)
hold off
The estimated parameters for ‘a’ are ‘B1(1)’ and ‘B2(1,:)’, and for ‘b’ in the second row for both.
I use fminsearch and norm here because everyone has them. Use other parameter estimation functions if you wish, especially if you want confidence intervals on the parameters, since my code does not calculate them. My code will work with them without other changes, other than substituting them for my fminsearch calls. The code is straightforward, creating the ‘PT’ matrix for power ‘P’ and time ‘T’, and a corresponding vector for weight ‘W’. I will let you explore my code to see how it works.
The ‘Q’ variable I originally used to be certain the indexing calculations work correctly. I am keeping it in the posted code (commented-out) so you can un-comment it and use it if you want to see how the loop indexing works to segment the rows of ‘PT’ and ‘W’ for all the plots, and for the second loop regressions.

2 Comments

hello Dear Mr Strider i appreciate for your answer and thank you i tried it and simulated ,i make out an equation of W=0.0062*P*exp(-0.0057*P*T); as my final model equation ,but it is fitting bad to the experimental datas when i plotted again generated weight values at different power in time .is my equation correct ?i replaced the B1 and B2 to my general equation only
My pleasure.
My code works with the data you provided, and it should work with new data. You may have to experiment with different initial parameter estimates (in my code [0.001; 0.1]), since nonlinear parameter estimation is sensitive to the initial estimates.
If my Answer helps you solve your problem, please Accept it!

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!