Some confusion in my script for lsqcurvefit

조회 수: 1 (최근 30일)
Sam Mahdi
Sam Mahdi 2019년 8월 7일
댓글: Sam Mahdi 2019년 8월 8일
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');
xdata=[P L]
fun=@(x,xdata) (B+x(1)-sqrt(((B+x(1)).^2)-4.*A.*C))./(2.*A)
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 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
So, C is a row vector while A is a column vector, therefore in the anonymous function
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개)

Community Treasure Hunt

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

Start Hunting!

Translated by