Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Using fittype for three dimensions

1 Ansicht (letzte 30 Tage)
Colin Lynch
Colin Lynch am 15 Mär. 2018
Geschlossen: MATLAB Answer Bot am 20 Aug. 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?

Antworten (1)

Prajit T R
Prajit T R am 22 Mär. 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

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by