-1

I have to fit the dots, results of measurements, by an exponential function on Matlab. My profesor asked me to use only

  • fminsearch
  • polyval
  • polyfit

One of them or both. I have to find the parameters a and b (the value) which are fitting it.

There is the lines I wrote :

x=[1:10:70]
y=[0:10:70]
x=[12.5,11.8,10.8,10.9,6.5,6.2,6.1,5.423,4.625]
y=[0,0.61,1.3,1.4,14.9,18.5,20.1,29.7,58.2]
xlabel('Conductivité')
ylabel('Inductance')

The function has the form a*e^(-b*x) +c

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
  • I don’t see a question in your post. You are just telling us what **you** need to work on. Please be specific about the question you want people to answer. – Cris Luengo Sep 22 '21 at 12:53

1 Answers1

0

Well polyfit and polyval are only usefull for working with polynomials. So you would have to write a minimization problem of the form min(f(x)).

functionToMinimize = @(pars, x, y)(norm(pars(1).*exp(-pars(2).*x) - y));
targetFunctionForFminseardch = @(pars)(functionToMinimize(pars, x, y));
minPars = fminsearch(targetFunctionForFminseardch, [0, 1])

Read up on anonymous functions and the use of vector norms if you have questions how to construct such a minimization problem.

Your code also has some flaws. Why are you defining x and y twice when you only want to use the actual measured data?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Robert_G
  • 19
  • 4
  • 1
    If you take the logarithm you get polynomials. – RPM Sep 15 '21 at 20:32
  • or you could use `fit` and `fittype` as in [https://www.mathworks.com/help/curvefit/exponential.html] – Azim J Sep 15 '21 at 21:26
  • Oh yeah, that's right! Using log before running the fminsearch should help, since its only a linear regression problem so fminsearch would be quite a bit of overkill. Thanks for the input! – Robert_G Sep 16 '21 at 13:00