Interpolator surface
$begingroup$
Writing:
Clear[u, v];
{a0, b0, c0} = {1, 2, 3};
f = ((x/a)^2 + (y/b)^2) c;
g = {a0 Sqrt[u] Cos[v], b0 Sqrt[u] Sin[v], c0 u};
h = {};
For[u = 0, u <= 1, u = u + 0.05,
For[v = 0, v <= 2 Pi, v = v + 0.05,
h = Join[h, {g}]
]
];
FindFit[h, f, {{a, a0}, {b, b0}, {c, c0}}, {x, y}]
I get:
{a -> 1., b -> 2., c -> 3.}
that's exactly how much you want.
Unfortunately a0, b0, c0
in reality I do not know them, so I should write:
FindFit[h, f, {a, b, c}, {x, y}]
I get:
{a -> 0.533886, b -> 1.06777, c -> 0.855104}
which is a result very far from what is expected. How could I fix it?
calculus-and-analysis fitting interpolation
$endgroup$
add a comment |
$begingroup$
Writing:
Clear[u, v];
{a0, b0, c0} = {1, 2, 3};
f = ((x/a)^2 + (y/b)^2) c;
g = {a0 Sqrt[u] Cos[v], b0 Sqrt[u] Sin[v], c0 u};
h = {};
For[u = 0, u <= 1, u = u + 0.05,
For[v = 0, v <= 2 Pi, v = v + 0.05,
h = Join[h, {g}]
]
];
FindFit[h, f, {{a, a0}, {b, b0}, {c, c0}}, {x, y}]
I get:
{a -> 1., b -> 2., c -> 3.}
that's exactly how much you want.
Unfortunately a0, b0, c0
in reality I do not know them, so I should write:
FindFit[h, f, {a, b, c}, {x, y}]
I get:
{a -> 0.533886, b -> 1.06777, c -> 0.855104}
which is a result very far from what is expected. How could I fix it?
calculus-and-analysis fitting interpolation
$endgroup$
add a comment |
$begingroup$
Writing:
Clear[u, v];
{a0, b0, c0} = {1, 2, 3};
f = ((x/a)^2 + (y/b)^2) c;
g = {a0 Sqrt[u] Cos[v], b0 Sqrt[u] Sin[v], c0 u};
h = {};
For[u = 0, u <= 1, u = u + 0.05,
For[v = 0, v <= 2 Pi, v = v + 0.05,
h = Join[h, {g}]
]
];
FindFit[h, f, {{a, a0}, {b, b0}, {c, c0}}, {x, y}]
I get:
{a -> 1., b -> 2., c -> 3.}
that's exactly how much you want.
Unfortunately a0, b0, c0
in reality I do not know them, so I should write:
FindFit[h, f, {a, b, c}, {x, y}]
I get:
{a -> 0.533886, b -> 1.06777, c -> 0.855104}
which is a result very far from what is expected. How could I fix it?
calculus-and-analysis fitting interpolation
$endgroup$
Writing:
Clear[u, v];
{a0, b0, c0} = {1, 2, 3};
f = ((x/a)^2 + (y/b)^2) c;
g = {a0 Sqrt[u] Cos[v], b0 Sqrt[u] Sin[v], c0 u};
h = {};
For[u = 0, u <= 1, u = u + 0.05,
For[v = 0, v <= 2 Pi, v = v + 0.05,
h = Join[h, {g}]
]
];
FindFit[h, f, {{a, a0}, {b, b0}, {c, c0}}, {x, y}]
I get:
{a -> 1., b -> 2., c -> 3.}
that's exactly how much you want.
Unfortunately a0, b0, c0
in reality I do not know them, so I should write:
FindFit[h, f, {a, b, c}, {x, y}]
I get:
{a -> 0.533886, b -> 1.06777, c -> 0.855104}
which is a result very far from what is expected. How could I fix it?
calculus-and-analysis fitting interpolation
calculus-and-analysis fitting interpolation
asked 2 days ago
TeMTeM
2,022621
2,022621
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
There are no differences in the predictions. What you have is an over-parameterized model. You have attempted to fit too many parameters. The basic model is
$$f=a_x x^2+a_y y^2$$
There are really only 2 parameters to fit.
sol0 = FindFit[h, f, {{a, a0}, {b, b0}, {c, c0}}, {x, y}]
(* {a -> 1., b -> 2., c -> 3.} *)
f /. sol0 // Expand
(* 3. x^2 + 0.75 y^2 *)
sol1 = FindFit[h, f, {a, b, c}, {x, y}]
(* {a -> 0.533886, b -> 1.06777, c -> 0.855104} *)
f /. sol1 // Expand
(* 3. x^2 + 0.75 y^2 *)
$endgroup$
$begingroup$
Sometimes I think I should take a break. Thank you so much for opening my eyes!
$endgroup$
– TeM
2 days ago
1
$begingroup$
Same here. You might consider just using $(x/a)^2 + (y/b)^2$ which is just setting $c=1$ if the parameters $a$ and $b$ are easier to interpret. Also, using the mean of the $x$ and $y$ values for the starting values for $a$ and $b$ might be more numerically stable if the $x$'s and $y$'s are very large or very small.
$endgroup$
– JimB
2 days ago
add a comment |
$begingroup$
This is not an answer, but a hint on how to improve your coding by coding in a more functional style. Functional code is almost always more concise and more efficient than procedural code.
{a0, b0, c0} = {1, 2, 3};
g[a_, b_, c_] = {a Sqrt[#1] Cos[#2], b Sqrt[#1] Sin[#2], c #1} &;
h = Table[g[a0, b0, c0][u, v], {u, 0, 1, .05}, {v, 0, 2 π, .05}] // Catenate;
$endgroup$
$begingroup$
Actually this was my first approach, but not knowingCatenate
I left it. Thank you, very useful!
$endgroup$
– TeM
yesterday
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f189887%2finterpolator-surface%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
There are no differences in the predictions. What you have is an over-parameterized model. You have attempted to fit too many parameters. The basic model is
$$f=a_x x^2+a_y y^2$$
There are really only 2 parameters to fit.
sol0 = FindFit[h, f, {{a, a0}, {b, b0}, {c, c0}}, {x, y}]
(* {a -> 1., b -> 2., c -> 3.} *)
f /. sol0 // Expand
(* 3. x^2 + 0.75 y^2 *)
sol1 = FindFit[h, f, {a, b, c}, {x, y}]
(* {a -> 0.533886, b -> 1.06777, c -> 0.855104} *)
f /. sol1 // Expand
(* 3. x^2 + 0.75 y^2 *)
$endgroup$
$begingroup$
Sometimes I think I should take a break. Thank you so much for opening my eyes!
$endgroup$
– TeM
2 days ago
1
$begingroup$
Same here. You might consider just using $(x/a)^2 + (y/b)^2$ which is just setting $c=1$ if the parameters $a$ and $b$ are easier to interpret. Also, using the mean of the $x$ and $y$ values for the starting values for $a$ and $b$ might be more numerically stable if the $x$'s and $y$'s are very large or very small.
$endgroup$
– JimB
2 days ago
add a comment |
$begingroup$
There are no differences in the predictions. What you have is an over-parameterized model. You have attempted to fit too many parameters. The basic model is
$$f=a_x x^2+a_y y^2$$
There are really only 2 parameters to fit.
sol0 = FindFit[h, f, {{a, a0}, {b, b0}, {c, c0}}, {x, y}]
(* {a -> 1., b -> 2., c -> 3.} *)
f /. sol0 // Expand
(* 3. x^2 + 0.75 y^2 *)
sol1 = FindFit[h, f, {a, b, c}, {x, y}]
(* {a -> 0.533886, b -> 1.06777, c -> 0.855104} *)
f /. sol1 // Expand
(* 3. x^2 + 0.75 y^2 *)
$endgroup$
$begingroup$
Sometimes I think I should take a break. Thank you so much for opening my eyes!
$endgroup$
– TeM
2 days ago
1
$begingroup$
Same here. You might consider just using $(x/a)^2 + (y/b)^2$ which is just setting $c=1$ if the parameters $a$ and $b$ are easier to interpret. Also, using the mean of the $x$ and $y$ values for the starting values for $a$ and $b$ might be more numerically stable if the $x$'s and $y$'s are very large or very small.
$endgroup$
– JimB
2 days ago
add a comment |
$begingroup$
There are no differences in the predictions. What you have is an over-parameterized model. You have attempted to fit too many parameters. The basic model is
$$f=a_x x^2+a_y y^2$$
There are really only 2 parameters to fit.
sol0 = FindFit[h, f, {{a, a0}, {b, b0}, {c, c0}}, {x, y}]
(* {a -> 1., b -> 2., c -> 3.} *)
f /. sol0 // Expand
(* 3. x^2 + 0.75 y^2 *)
sol1 = FindFit[h, f, {a, b, c}, {x, y}]
(* {a -> 0.533886, b -> 1.06777, c -> 0.855104} *)
f /. sol1 // Expand
(* 3. x^2 + 0.75 y^2 *)
$endgroup$
There are no differences in the predictions. What you have is an over-parameterized model. You have attempted to fit too many parameters. The basic model is
$$f=a_x x^2+a_y y^2$$
There are really only 2 parameters to fit.
sol0 = FindFit[h, f, {{a, a0}, {b, b0}, {c, c0}}, {x, y}]
(* {a -> 1., b -> 2., c -> 3.} *)
f /. sol0 // Expand
(* 3. x^2 + 0.75 y^2 *)
sol1 = FindFit[h, f, {a, b, c}, {x, y}]
(* {a -> 0.533886, b -> 1.06777, c -> 0.855104} *)
f /. sol1 // Expand
(* 3. x^2 + 0.75 y^2 *)
answered 2 days ago
JimBJimB
17.3k12763
17.3k12763
$begingroup$
Sometimes I think I should take a break. Thank you so much for opening my eyes!
$endgroup$
– TeM
2 days ago
1
$begingroup$
Same here. You might consider just using $(x/a)^2 + (y/b)^2$ which is just setting $c=1$ if the parameters $a$ and $b$ are easier to interpret. Also, using the mean of the $x$ and $y$ values for the starting values for $a$ and $b$ might be more numerically stable if the $x$'s and $y$'s are very large or very small.
$endgroup$
– JimB
2 days ago
add a comment |
$begingroup$
Sometimes I think I should take a break. Thank you so much for opening my eyes!
$endgroup$
– TeM
2 days ago
1
$begingroup$
Same here. You might consider just using $(x/a)^2 + (y/b)^2$ which is just setting $c=1$ if the parameters $a$ and $b$ are easier to interpret. Also, using the mean of the $x$ and $y$ values for the starting values for $a$ and $b$ might be more numerically stable if the $x$'s and $y$'s are very large or very small.
$endgroup$
– JimB
2 days ago
$begingroup$
Sometimes I think I should take a break. Thank you so much for opening my eyes!
$endgroup$
– TeM
2 days ago
$begingroup$
Sometimes I think I should take a break. Thank you so much for opening my eyes!
$endgroup$
– TeM
2 days ago
1
1
$begingroup$
Same here. You might consider just using $(x/a)^2 + (y/b)^2$ which is just setting $c=1$ if the parameters $a$ and $b$ are easier to interpret. Also, using the mean of the $x$ and $y$ values for the starting values for $a$ and $b$ might be more numerically stable if the $x$'s and $y$'s are very large or very small.
$endgroup$
– JimB
2 days ago
$begingroup$
Same here. You might consider just using $(x/a)^2 + (y/b)^2$ which is just setting $c=1$ if the parameters $a$ and $b$ are easier to interpret. Also, using the mean of the $x$ and $y$ values for the starting values for $a$ and $b$ might be more numerically stable if the $x$'s and $y$'s are very large or very small.
$endgroup$
– JimB
2 days ago
add a comment |
$begingroup$
This is not an answer, but a hint on how to improve your coding by coding in a more functional style. Functional code is almost always more concise and more efficient than procedural code.
{a0, b0, c0} = {1, 2, 3};
g[a_, b_, c_] = {a Sqrt[#1] Cos[#2], b Sqrt[#1] Sin[#2], c #1} &;
h = Table[g[a0, b0, c0][u, v], {u, 0, 1, .05}, {v, 0, 2 π, .05}] // Catenate;
$endgroup$
$begingroup$
Actually this was my first approach, but not knowingCatenate
I left it. Thank you, very useful!
$endgroup$
– TeM
yesterday
add a comment |
$begingroup$
This is not an answer, but a hint on how to improve your coding by coding in a more functional style. Functional code is almost always more concise and more efficient than procedural code.
{a0, b0, c0} = {1, 2, 3};
g[a_, b_, c_] = {a Sqrt[#1] Cos[#2], b Sqrt[#1] Sin[#2], c #1} &;
h = Table[g[a0, b0, c0][u, v], {u, 0, 1, .05}, {v, 0, 2 π, .05}] // Catenate;
$endgroup$
$begingroup$
Actually this was my first approach, but not knowingCatenate
I left it. Thank you, very useful!
$endgroup$
– TeM
yesterday
add a comment |
$begingroup$
This is not an answer, but a hint on how to improve your coding by coding in a more functional style. Functional code is almost always more concise and more efficient than procedural code.
{a0, b0, c0} = {1, 2, 3};
g[a_, b_, c_] = {a Sqrt[#1] Cos[#2], b Sqrt[#1] Sin[#2], c #1} &;
h = Table[g[a0, b0, c0][u, v], {u, 0, 1, .05}, {v, 0, 2 π, .05}] // Catenate;
$endgroup$
This is not an answer, but a hint on how to improve your coding by coding in a more functional style. Functional code is almost always more concise and more efficient than procedural code.
{a0, b0, c0} = {1, 2, 3};
g[a_, b_, c_] = {a Sqrt[#1] Cos[#2], b Sqrt[#1] Sin[#2], c #1} &;
h = Table[g[a0, b0, c0][u, v], {u, 0, 1, .05}, {v, 0, 2 π, .05}] // Catenate;
answered 2 days ago
m_goldbergm_goldberg
85k872196
85k872196
$begingroup$
Actually this was my first approach, but not knowingCatenate
I left it. Thank you, very useful!
$endgroup$
– TeM
yesterday
add a comment |
$begingroup$
Actually this was my first approach, but not knowingCatenate
I left it. Thank you, very useful!
$endgroup$
– TeM
yesterday
$begingroup$
Actually this was my first approach, but not knowing
Catenate
I left it. Thank you, very useful!$endgroup$
– TeM
yesterday
$begingroup$
Actually this was my first approach, but not knowing
Catenate
I left it. Thank you, very useful!$endgroup$
– TeM
yesterday
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f189887%2finterpolator-surface%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown