Sum Squared Errors for 3 parameters

4 views (last 30 days)
Emily Greulich
Emily Greulich on 26 Feb 2020
Answered: Jeff Miller on 27 Feb 2020
Im trying to find the sum of squared errors (SSE) for two equations with 3 parameters. Im using nested for loops but I'm getting a massive number and its not stepping through the parameters correctly.
Here is the entire code. I need help with the for loops and getting them to work right.
%
e = 2.71828;
%X1=X2=X3
OP = 1;
%exponents
g = 1;
h = OP;
i = 2*OP;
%alpha
a = (e^(OP+2*OP))/(OP^(g-1) * OP^h * OP^i);
%SSE
E = 0;
SSE = 0;
for X1 = 0:10
for X2 = 0:10
for X3 = 0:10
end
end
F = a*X1*X2*X3^2;
f = X1*e^(X2+2*X3);
E = (f - F)^2;
SSE = SSE + E
end
  2 Comments
Naveed Ahmed
Naveed Ahmed on 26 Feb 2020
Hi
Apparently there does not seem to be any issue with the code, as it is doing as coded. Practically speaking, SSE is calculated with actual and predicted values, both of these are calculated in your code that are presumable f and F. Since you are taking cube and taking exponential, it is expected that value would be high. So, to answer you better, can you elaborate bit more about the nature of f and F and how do you come up with these equations?
Good Luck
Emily Greulich
Emily Greulich on 26 Feb 2020
Its a power law approximation and I'm trying to see the error between the approx and the orginial at different operating points. The orginial equation is F(X1, X2, X3) = X1 . exp(X2 + 2X3)

Sign in to comment.

Answers (1)

Jeff Miller
Jeff Miller on 27 Feb 2020
It looks like your X2 and X3 'for' loops aren't doing anything, since there is no code between their 'for' and 'end' statements. Not sure what you are actually trying to compute, but it looks like it would make more sense to move the computation statements (computing F down to SSE) before those two end statements.

Categories

Find more on Startup and Shutdown 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!