Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Using fittype for three dimensions

1 visualización (últimos 30 días)
Colin Lynch
Colin Lynch el 15 de Mzo. de 2018
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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?

Respuestas (1)

Prajit T R
Prajit T R el 22 de Mzo. de 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

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by