Why does fit type not accept my convoluted function as input? (MATLAB)
2 views (last 30 days)
Show older comments
The ultimate goal is to fit a costum equation to experimental data by (Z = f(X,Y)). The general equation is given by:
Rw = conv2([zeros(4095,11);((1/(3*redmu+mu_a))^(-3/2)).*(X).^(-5/2).*...
exp(-mu_a*2.*(X)).*exp(-(Y.^2)./(4/(3*redmu+mu_a)*2.*X))],IRF,'valid');
Where mu_a and redmu are the fitting parameters.
The generalized piece of code I wrote can be seen below
IRF = rand(4096,1);
X = (1:4096)';
Y = 1:11;
ft_notworking = fittype(@(mu_a,redmu,X,Y) conv2([zeros(4095,11);((1/(3*redmu+mu_a))^(-3/2)).*(X).^(-5/2).*...
exp(-mu_a*2.*(X)).*exp(-(Y.^2)./(4/(3*redmu+mu_a)*2.*X))],IRF,'valid'),'independent',{'X','Y'},'coefficient',{'mu_a','redmu'});
It gives an error: "Dimensions of arrays being concatenatedare not consistent.". That is strange as I use the
zeros(4095,11)
and
shape = 'valid'
for the conv2 function to make sure the shape of Rw = 4096x11. Just as the input parameters `X` and `Y` are spanning. If I get rid of the convolution (as shown below) I don't get any error. This makes me suspect that the convolution and fittype function don't work together very well.
ft = fittype(@(mu_a,redmu,x,y) (((1/(3*redmu+mu_a))^(-3/2)).*x.^(-5/2).*...
exp(-mu_a*2.*(x)).*exp(-(y.^2)./(4/(3*redmu+mu_a)*2.*x))),...
'independent',{'x','y'},'coefficient',{'mu_a','redmu'})
What I don't get is this: Both Rw and the unconvoluted equation have the same shape `4096x11`, but for Rw we get an error and for the other we don't.
Additionally I tried to write a function that calculates Rw (the convoluted function) in the desired dimensions 4096x11 and named it test.m. I call the function in the fittype function.
ft = fittype('test( tw, rw, mu_a,redmu)','independent',{'tw','rw'},'coefficient',{'mu_a','redmu'})
I get the same error as before. So it looks like the convolution messes it up. That is unfortunate as I need the convolution. Is anyone able to help me with this problem?
Best regards
P.S Here is a script you could use to test stuff
redmu = 10;
mu_a = 0;
IRF = rand(4096,1);
X = (1:4096)';
Y = 1:11;
Rw = conv2([zeros(4095,11);((1/(3*redmu+mu_a))^(-3/2)).*(X).^(-5/2).*...
exp(-mu_a*2.*(X)).*exp(-(Y.^2)./(4/(3*redmu+mu_a)*2.*X))],IRF,'valid');
ft_notworking = fittype(@(mu_a,redmu,X,Y) conv2([zeros(4095,11);((1/(3*redmu+mu_a))^(-3/2)).*(X).^(-5/2).*...
exp(-mu_a*2.*(X)).*exp(-(Y.^2)./(4/(3*redmu+mu_a)*2.*X))],IRF,'valid'),'independent',{'X','Y'},'coefficient',{'mu_a','redmu'});
ft_working = fittype(@(mu_a,redmu,X,Y) (((1/(3*redmu+mu_a))^(-3/2)).*(X).^(-5/2).*...
exp(-mu_a*2.*(X)).*exp(-(Y.^2)./(4/(3*redmu+mu_a)*2.*X))),'independent',{'X','Y'},'coefficient',{'mu_a','redmu'});
0 Comments
Answers (0)
See Also
Categories
Find more on Linear and Nonlinear Regression 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!