Some confusion in my script for lsqcurvefit

2 次查看(过去 30 天)
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).

采纳的回答

Guillaume
Guillaume 2019-8-7
编辑:Guillaume 2019-8-7
You know that (the badly named) P and L are both column vectors, then you have
A=P; %how about using meaningful names for the variables
C=L'; %NOTE THE TRANSPOSE
So, C is a row vector while A is a column vector, therefore in the anonymous function
A.*C
will be a square matrix of size numel(P) x numel(P) (in your case 7x7).
  1 个评论
Sam Mahdi
Sam Mahdi 2019-8-8
Thank you, didn't see that typo there. Also, the P and L are abbreviations for protein and ligand, and the A,B,C, is for the quadratic equation I have set up.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by