# How to find an unknown parameter from a equation fitted to a data-set in MATLAB 2016b ?

3 views (last 30 days)
SANJIB MAJUMDER on 5 Mar 2017
Edited: John D'Errico on 5 Mar 2017
I have a data set for x values and y values.Now I want to solve an unknown parameter n from the equation y=2.t(1-cos(x)(n-1)/(n.p-p(1-cos(x))),where t,p are known.How to write the code to get value of n from the fitted plot? Thanks in advance

John D'Errico on 5 Mar 2017
So, you have this equation:
y = 2*t*(1-cos(x)*(n-1)/(n*p-p*(1-cos(x)))
I've rewritten it above, putting in multiplies where you used . or you used nothing at all. Thus cos(x)(n-1) is not a valid expression. You should get used to writing things so they are readable.
The problem is, this is not valid either, as I wrote it, since the parens are unbalanced. See that there are 6 ( characters in that line, and only 5 ) in there. I never added or deleted any parens. That means your expression makes no mathematical sense.
IF you show me how the parens should be written, then I can show you how to compute n. For example, should it have been this:
y = 2*t*(1-cos(x)*(n-1))/(n*p-p*(1-cos(x)))
or this, where the extra parens was added at the end?
y = 2*t*(1-cos(x)*(n-1)/(n*p-p*(1-cos(x))))
The two expressions are significantly different.
In the first case, solving for n, I would get this relation:
n = (2*t*(1 + cos(x)) + p*y*(1 - cos(x)))/(p*y + 2*t*cos(x))
In the second case (assuming my algebra was correct at this time of day) I might have gotten this:
n = (p*y*(1 - cos(x)) + 2*t*cos(x) - 2*p*t*(1 - cos(x)))/(p*y - 2*p*t + 2*t*cos(x))
But you have multiple values for x and y, thus pairs of points such that these equations should hold true.
x=michel(:,1);
y=michel(:,2);
Then compute the mean, but in those expressions, use ./ instead of /, and .* instead of * in the correct expression. The dotted operators are element-wise multiplies and divides.
You don't need .* between two scalar values, but whenever you have vectors in the expression, you need to use the element-wise operators.
So in the first expression, I would get:
n = mean((2*t*(1 + cos(x)) + p*y.*(1 - cos(x)))./(p*y + 2*t*cos(x)));
In the second case, it should be this:
n = mean((p*y.*(1 - cos(x)) + 2*t*cos(x) - 2*p*t*(1 - cos(x)))./(p*y - 2*p*t + 2*t*cos(x)));
The idea is that the simplest estimator of n is simply the arithmetic mean of all of those possible results for n, given all the sets of x and y.
In fact though, if your original equation had noise in it, I pulled a fast one, because the best estimator of n should really be estimated using a nonlinear least squares estimate, based on the original equation. We would get a subtly different result from computing the mean as I did above.
Had you attached your data as a .mat file to a comment, or to your original question, I could now show how to do all of this more properly as a nonlinear least squares estimation. But first, tell me where the extra paren was supposed to be, as I don't want to do it all twice.
John D'Errico on 5 Mar 2017
Edited: John D'Errico on 5 Mar 2017
HUH? What are you talking about?
For example:
X0 = rand(1,5)
X0 =
0.711215780433683 0.22174673401724 0.117417650855806 0.296675873218327 0.318778301925882
Y0 = rand(1,5)
Y0 =
0.424166759713807 0.507858284661118 0.085515797090044 0.262482234698333 0.801014622769739
h = plot(X0,Y0);
h.XData - X0
ans =
0 0 0 0 0
As you can see, when I extracted the data from the plot, I get the EAXCT value. Not a rounded version.
(h.XData - X0) == 0
ans =
1×5 logical array
1 1 1 1 1
I imagine that you are somehow trying to use the values reported to the command window, which will be rounded to 5 significant digits by default. That is simply wrong to do on your part, IF you are doing that. Otherwise, there is NO rounding done, if you CAREFULLY do as I told you to do.

kowshik Thopalli on 5 Mar 2017
I might be wrong here. If you know all of these values and dont know only n cant you just find n through algebra. I mean solving for n from the equation you have given,I get n as n= ((1-cosx)*(p*y-2*t))/((p*y-2*t(1-cos(x))). and now implementing this in Matlab is trivial.
kowshik Thopalli on 5 Mar 2017
Ofcourse.That is expected. As I mentioned in my comment earlier, the code that I gave is for getting data points if you have only the plot and no access to the data points. Since you have the data points this is an parameter estimation problem as pointed out by John