Some confusion in my script for lsqcurvefit
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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).
0 Commenti
Risposta accettata
Guillaume
il 7 Ago 2019
Modificato: Guillaume
il 7 Ago 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).
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Quadratic Programming and Cone Programming in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!