# how to calculate optimal value of a unknown constant of an equation with known data points?

7 views (last 30 days)
pooja sudha on 10 Sep 2020
Commented: pooja sudha on 11 Sep 2020
Hey, I wanted to solve for the optimal value of constant. I have data points of the equation .
equation is:
y= 1/sqrt(k^2+x^2)

Walter Roberson on 11 Sep 2020
k0 = rand() * 10;
bestk = lsqcurvefit( @(k,x)1./sqrt(k.^2+x.^2), k0, x, y);
pooja sudha on 11 Sep 2020
Hey Thanks Adam and Walter , I found the result :)

Adam Danz on 10 Sep 2020
k = sqrt((1/y)^2 - x^2)
Adam Danz on 11 Sep 2020
% assign demo values
k = 2.2; % = 2.2
x = 1:10; % = [1,2,3,4,5,6,7,8,9,10]
y = 1./sqrt(k^2 + x.^2); % = [0.41 0.33 0.26 0.21 0.18 0.15 0.13 0.12 0.10 0.09]
% Solve for k
k = sqrt((1./y).^2 - x.^2) % = [2.2 2.2 2.2 2.2 2.2 2.2 2.2 2.2 2.2 2.2 ]
k = sqrt((1/y(1))^2 - x(1)^2) % = 2.2
Or, as Walter shows, you can use mean(), mode(), median().

### Categories

Find more on Line Plots in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by