sayid jetzenden
sayid jetzenden

Reputation: 153

Matlab - approximation issue

I'm trying to approximate several points with a curve. My script looks like this:

T = [ 0 5.67 13.28 20.18 26.84 37.74];
T = T';
eta = [0 54.33 70.91 73.56 73.29 76.];
eta = eta'
f4 = fit(eta, T, 'poly2');
f5 = fit(eta, T, 'poly3');

The plot looks like the one below but i need the curve not to pass through negative numbers.

plot .

Any idea how to implement the limits of the curve?

Upvotes: 0

Views: 87

Answers (2)

sayid jetzenden
sayid jetzenden

Reputation: 153

I figured out the solution. I didn't read the documentation in matlab thoroughly. So it should be :

f5 = fit(eta, T, 'exp1');

Upvotes: 2

I think this is quite broad question that depends on the curve fitting algorithms. As an example based on the Matlab information about fit listed here, I did the following code segment. It gives a non-negative curve. But I hope someone will give you a better answer.

T = [0 5.67 13.28 20.18 26.84 37.74]';
eta = [0 54.33 70.91 73.56 73.29 76.]';
f4 = fit(eta, T, 'poly2');
f5 = fit(eta, T, 'poly3');

fo = fitoptions('Method','NonlinearLeastSquares',...
               'Lower',[0,0],...
               'Upper',[Inf,max(eta)],...
               'StartPoint',[0 0]);
ft = fittype('a*(x-b)^n','problem','n','options',fo);
[curve3,gof3] = fit(eta,T,ft,'problem',2);

plot(curve3,eta,T);

Output:

enter image description here

Upvotes: 0

Related Questions