Is there a way I can fix my data/code to fit this NonLinearModelFit?
When I tried to run this code:
Data1 = FinancialData["^DJI", {{2003, 10, 21}, {2007, 10, 09}}];
Data2 = {{{{AbsoluteTime[#1] - AbsoluteTime[{2003, 10, 21}]}/
86400}, #2} & @@@ Data1};
Data3 = Data2 //. {x_List} :> x;
Data4 = Data3 //. {x_List} :> x;
Data5 = Data4 //. {x_List} :> x;
Data6 = ArrayReshape[Data5 = Data4 //. {x_List} :> x, {1000, 2}];
NonlinearModelFit[Data6, {10^(a + b u^z +
c u^z Cos[[Phi] + [Omega] Log10[u]]), {b < 0, -1 < c < 1, 0.1` <= z <=
0.9`, 4.8` <= [Omega] <= 13,0 <= [Phi] <= 2 [Pi]}}, {a, b, c, z,
[Omega], [Phi]}, u]
I get these following error messages:
The gradient is not a vector of real numbers at {a,b,c,z,[Omega],[Phi]} = {1.,-1.,0.8,0.82,5.62,0.628319}.
Evaluation of the gradient of function Experimental`NumericalFunction[<<1>>] failed at {1.,-1.,0.8,0.82,5.62,0.628319}.
What is causing this?
wolfram-mathematica
add a comment |
When I tried to run this code:
Data1 = FinancialData["^DJI", {{2003, 10, 21}, {2007, 10, 09}}];
Data2 = {{{{AbsoluteTime[#1] - AbsoluteTime[{2003, 10, 21}]}/
86400}, #2} & @@@ Data1};
Data3 = Data2 //. {x_List} :> x;
Data4 = Data3 //. {x_List} :> x;
Data5 = Data4 //. {x_List} :> x;
Data6 = ArrayReshape[Data5 = Data4 //. {x_List} :> x, {1000, 2}];
NonlinearModelFit[Data6, {10^(a + b u^z +
c u^z Cos[[Phi] + [Omega] Log10[u]]), {b < 0, -1 < c < 1, 0.1` <= z <=
0.9`, 4.8` <= [Omega] <= 13,0 <= [Phi] <= 2 [Pi]}}, {a, b, c, z,
[Omega], [Phi]}, u]
I get these following error messages:
The gradient is not a vector of real numbers at {a,b,c,z,[Omega],[Phi]} = {1.,-1.,0.8,0.82,5.62,0.628319}.
Evaluation of the gradient of function Experimental`NumericalFunction[<<1>>] failed at {1.,-1.,0.8,0.82,5.62,0.628319}.
What is causing this?
wolfram-mathematica
add a comment |
When I tried to run this code:
Data1 = FinancialData["^DJI", {{2003, 10, 21}, {2007, 10, 09}}];
Data2 = {{{{AbsoluteTime[#1] - AbsoluteTime[{2003, 10, 21}]}/
86400}, #2} & @@@ Data1};
Data3 = Data2 //. {x_List} :> x;
Data4 = Data3 //. {x_List} :> x;
Data5 = Data4 //. {x_List} :> x;
Data6 = ArrayReshape[Data5 = Data4 //. {x_List} :> x, {1000, 2}];
NonlinearModelFit[Data6, {10^(a + b u^z +
c u^z Cos[[Phi] + [Omega] Log10[u]]), {b < 0, -1 < c < 1, 0.1` <= z <=
0.9`, 4.8` <= [Omega] <= 13,0 <= [Phi] <= 2 [Pi]}}, {a, b, c, z,
[Omega], [Phi]}, u]
I get these following error messages:
The gradient is not a vector of real numbers at {a,b,c,z,[Omega],[Phi]} = {1.,-1.,0.8,0.82,5.62,0.628319}.
Evaluation of the gradient of function Experimental`NumericalFunction[<<1>>] failed at {1.,-1.,0.8,0.82,5.62,0.628319}.
What is causing this?
wolfram-mathematica
When I tried to run this code:
Data1 = FinancialData["^DJI", {{2003, 10, 21}, {2007, 10, 09}}];
Data2 = {{{{AbsoluteTime[#1] - AbsoluteTime[{2003, 10, 21}]}/
86400}, #2} & @@@ Data1};
Data3 = Data2 //. {x_List} :> x;
Data4 = Data3 //. {x_List} :> x;
Data5 = Data4 //. {x_List} :> x;
Data6 = ArrayReshape[Data5 = Data4 //. {x_List} :> x, {1000, 2}];
NonlinearModelFit[Data6, {10^(a + b u^z +
c u^z Cos[[Phi] + [Omega] Log10[u]]), {b < 0, -1 < c < 1, 0.1` <= z <=
0.9`, 4.8` <= [Omega] <= 13,0 <= [Phi] <= 2 [Pi]}}, {a, b, c, z,
[Omega], [Phi]}, u]
I get these following error messages:
The gradient is not a vector of real numbers at {a,b,c,z,[Omega],[Phi]} = {1.,-1.,0.8,0.82,5.62,0.628319}.
Evaluation of the gradient of function Experimental`NumericalFunction[<<1>>] failed at {1.,-1.,0.8,0.82,5.62,0.628319}.
What is causing this?
wolfram-mathematica
wolfram-mathematica
edited Jan 1 at 15:49
SandPiper
2,17931730
2,17931730
asked Jan 1 at 15:43
Lim Yang ShengLim Yang Sheng
61
61
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
First[Data6]
(* {0, 9747.64} *}
Has u = 0
and the function being fitted has Log10[u]
. Shift the u
values by 1.
Data7 = {First[#] + 1, Last[#]} & /@ Data6
Add a constraint on a
and fit
fit = NonlinearModelFit[
Data7, {10^(a + b u^z + c u^z Cos[[Phi] + [Omega] Log10[u]]), {a <
10, b < 0, -1 < c < 1, 0.1` <= z <= 0.9`,
4.8` <= [Omega] <= 13, 0 <= [Phi] <= 2 [Pi]}}, {a, b, c,
z, [Omega], [Phi]}, u]
Plot data and fit
Show[Plot[fit[u], {u, 1, 1450}], ListPlot[Data7]]
It is a pretty poor fit. May be able to get a better fit by altering the constraints.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53996771%2fis-there-a-way-i-can-fix-my-data-code-to-fit-this-nonlinearmodelfit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
First[Data6]
(* {0, 9747.64} *}
Has u = 0
and the function being fitted has Log10[u]
. Shift the u
values by 1.
Data7 = {First[#] + 1, Last[#]} & /@ Data6
Add a constraint on a
and fit
fit = NonlinearModelFit[
Data7, {10^(a + b u^z + c u^z Cos[[Phi] + [Omega] Log10[u]]), {a <
10, b < 0, -1 < c < 1, 0.1` <= z <= 0.9`,
4.8` <= [Omega] <= 13, 0 <= [Phi] <= 2 [Pi]}}, {a, b, c,
z, [Omega], [Phi]}, u]
Plot data and fit
Show[Plot[fit[u], {u, 1, 1450}], ListPlot[Data7]]
It is a pretty poor fit. May be able to get a better fit by altering the constraints.
add a comment |
First[Data6]
(* {0, 9747.64} *}
Has u = 0
and the function being fitted has Log10[u]
. Shift the u
values by 1.
Data7 = {First[#] + 1, Last[#]} & /@ Data6
Add a constraint on a
and fit
fit = NonlinearModelFit[
Data7, {10^(a + b u^z + c u^z Cos[[Phi] + [Omega] Log10[u]]), {a <
10, b < 0, -1 < c < 1, 0.1` <= z <= 0.9`,
4.8` <= [Omega] <= 13, 0 <= [Phi] <= 2 [Pi]}}, {a, b, c,
z, [Omega], [Phi]}, u]
Plot data and fit
Show[Plot[fit[u], {u, 1, 1450}], ListPlot[Data7]]
It is a pretty poor fit. May be able to get a better fit by altering the constraints.
add a comment |
First[Data6]
(* {0, 9747.64} *}
Has u = 0
and the function being fitted has Log10[u]
. Shift the u
values by 1.
Data7 = {First[#] + 1, Last[#]} & /@ Data6
Add a constraint on a
and fit
fit = NonlinearModelFit[
Data7, {10^(a + b u^z + c u^z Cos[[Phi] + [Omega] Log10[u]]), {a <
10, b < 0, -1 < c < 1, 0.1` <= z <= 0.9`,
4.8` <= [Omega] <= 13, 0 <= [Phi] <= 2 [Pi]}}, {a, b, c,
z, [Omega], [Phi]}, u]
Plot data and fit
Show[Plot[fit[u], {u, 1, 1450}], ListPlot[Data7]]
It is a pretty poor fit. May be able to get a better fit by altering the constraints.
First[Data6]
(* {0, 9747.64} *}
Has u = 0
and the function being fitted has Log10[u]
. Shift the u
values by 1.
Data7 = {First[#] + 1, Last[#]} & /@ Data6
Add a constraint on a
and fit
fit = NonlinearModelFit[
Data7, {10^(a + b u^z + c u^z Cos[[Phi] + [Omega] Log10[u]]), {a <
10, b < 0, -1 < c < 1, 0.1` <= z <= 0.9`,
4.8` <= [Omega] <= 13, 0 <= [Phi] <= 2 [Pi]}}, {a, b, c,
z, [Omega], [Phi]}, u]
Plot data and fit
Show[Plot[fit[u], {u, 1, 1450}], ListPlot[Data7]]
It is a pretty poor fit. May be able to get a better fit by altering the constraints.
answered Jan 1 at 21:24
Rohit NamjoshiRohit Namjoshi
31718
31718
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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.
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%2fstackoverflow.com%2fquestions%2f53996771%2fis-there-a-way-i-can-fix-my-data-code-to-fit-this-nonlinearmodelfit%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