# calculation x-value, given the y-value of a discrete function

5 views (last 30 days)
marie deseyn on 18 Feb 2020
Answered: KSSV on 18 Feb 2020
I want to calculate the x-value of a given function in a given y, but my function is only available in discrete points how can I do that?
This is the function I made to make the function, what I basicly want to do is finding the x-value where 'plot(squeeze(chi2(1:20,15,10)))' intersects with minchi.
C=10;
x0=15;
a=9;
xen =linspace(0,60);
xen =linspace(0,60,100)';
y= C./ sqrt((xen.^2-x0^2).^2+a*xen.^2);
naruisy = y + randn(100,1)*0.01;%amplitude = *0.04
plot(xen,y)
hold on
plot(xen,naruisy)
chi2 = zeros(20,20,20);
minchi2 = 100;
for a = linspace(1,20,20)
for b = linspace(1,20,20)
%fprintf('huidige index:%i\n', b)
for c = linspace(1,20,20)
somelementen = [];
ymetparam = c./ sqrt((xen.^2-b^2).^2+a*xen.^2);
somelementen = (naruisy- ymetparam).^2;
% plot(xen,naruisy)
% hold on
% plot(xen,ymetparam,'g')
% hold off
% pause(0.2)
chi2(a,b,c)=sum(somelementen)/(length(somelementen)-3);
if chi2(a,b,c) < minchi2
minchi2 = chi2(a,b,c);
minparam = [a,b,c];
%minchi2
end
end
end
end
plot(squeeze(chi2(9,15,1:20)))
hold on
minchi2
xplot=linspace(0,20,100);
yplot=xplot-xplot + minchi2;
plot(xplot,yplot)
hold on
yplot=xplot-xplot + 2*minchi2;
hold on
plot(xplot,yplot)
%%
%bij c_best en b_best de a bekijken
plot(squeeze(chi2(1:20,15,10)))
hold on
minchi2
xplot=linspace(0,20,100);
yplot=xplot-xplot + minchi2;
plot(xplot,yplot)
hold on
yplot=xplot-xplot + 2*minchi2;
hold on
plot(xplot,yplot)

KSSV on 18 Feb 2020