Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Using fittype for three dimensions

1 vue (au cours des 30 derniers jours)
Colin Lynch
Colin Lynch le 15 Mar 2018
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hello!
I am attempting to use the fittype function to fit a softmax surface to a sigmoid surface using only one coefficient, beta. I couldn't understand the literature on how to do this, so I attempted to do it in a for loop where I would only fit the two dimensional curve for one dependent axis, y, while iterating over the dependent surface, theta. The output would then be an array of the coefficients I need. My efforts resulted in this code:
x = linspace(0,1);
z = zeros(1,10);
for n = 1:10
theta = n/10;
y = x.^2./(x.^2 + theta.^2);
myfittype = fittype('1/(1+exp(beta*(theta-x)))', 'dependent',{'y'},'independent',{'x'}, 'coefficients',{'beta'});
myfit = fit(x',y',myfittype);
z(n) = myfit.beta;
end
The problem is that fittype doesn't recognize theta as an input variable, so its undefined right now. Does anyone know how to use fittype to directly fit surfaces, or how I can fix this particular for loop?

Réponses (1)

Prajit T R
Prajit T R le 22 Mar 2018
Hi Colin
The variable 'theta' is not being recognized by the fittype function- hence the error. Try this modified code instead:
x = linspace(0,1);
z = zeros(1,10);
for n = 1:10
theta = n/10;
y = x.^2./(x.^2 + theta.^2);
myfittype = fittype('1/(1+exp(beta*(theta-x)))', 'dependent',{'y'},'independent',{'x'}, 'coefficients',{'beta','theta'});
myfit = fit(x',y',myfittype);
z(n) = myfit.beta;
end
The only change is that 'theta' has been defined as a co-efficient.
Cheers

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by