Effacer les filtres
Effacer les filtres

Some confusion in my script for lsqcurvefit

2 vues (au cours des 30 derniers jours)
Sam Mahdi
Sam Mahdi le 7 Août 2019
Commenté : Sam Mahdi le 8 Août 2019
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).

Réponse acceptée

Guillaume
Guillaume le 7 Août 2019
Modifié(e) : Guillaume le 7 Août 2019
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 commentaire
Sam Mahdi
Sam Mahdi le 8 Août 2019
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Variables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by