Some confusion in my script for lsqcurvefit
Show older comments
Hello everyone,
I have somewhat of an issue I don't quite know how to resolve. I have a very simply code:
data1=load ('Concentrations.txt');
data2=load ('Titration.txt');
J=data2(:,1)
L=data1(:,1);
P=data1(:,2);
A=P;
B=P+L;
C=L';
xdata=[P L]
fun=@(x,xdata) (B+x(1)-sqrt(((B+x(1)).^2)-4.*A.*C))./(2.*A)
x0=[1]
x = lsqcurvefit(fun,x0,xdata,J)
The error I am getting is
Function value and YDATA sizes are not equal.
Now from my understanding, what is going on here is I have some unknown x(1), and this value changes while keeping xdata constant, to find a value that matches ydata. This then goes through each data point (i.e. each row or column in your xdata file), and does the same thing.
Now what this would imply is the output of the function F(x,xdata) is not the same as my ydata (therefore F(x,xdata-ydata) would be problematic). However, I have checked the sizes of all my vectors, and they all match.
>> whos J
Name Size Bytes Class Attributes
J 7x1 56 double
>> whos xdata
Name Size Bytes Class Attributes
xdata 7x2 112 double
>> whos P
Name Size Bytes Class Attributes
P 7x1 56 double
>> whos L
Name Size Bytes Class Attributes
L 7x1 56 double
Now in my situation, both P and L are changing each iteration (that's why it's a 7x2), so what I've attempted to do is have xdata be a matrix where one column is P and another L. I.E. for F(x,xdata(1)) it will take P(1,1) and L(1,2).
Accepted Answer
More Answers (0)
Categories
Find more on Particle & Nuclear Physics 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!