“Unable to prove literally” error when trying to create a symbolic function based on an existing function
I need to find inverse of virtual value function of lognormal random variables. This is what I tried to do:
syms flogn(x,p1,p2)
% assume(p2<=0); %Adding this doesn't change the error
flogn(x,p1,p2) = x - logncdf(x,p1,p2,'upper')/lognpdf(x,p1,p2);
glogn = finverse(flogn,x);
But I got the error:
Error using symengine
Unable to prove 'p2 <= 0' literally. Use 'isAlways' to test the statement mathematically.
Error in sym/subsindex (line 810)
X = find(mupadmex('symobj::logical',A.s,9)) - 1;
Error in sym/privsubsasgn (line 1085)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',varargin),R_tilde);
Error in sym/subsasgn (line 922)
C = privsubsasgn(L,R,inds:);
Error in logncdf>locallogncdf (line 73)
sigma(sigma <= 0) = NaN;
Error in logncdf (line 47)
[varargout1:max(1,nargout)] = locallogncdf(uflag,x,varargin:);
Error in Untitled5 (line 3)
flogn(x,p1,p2) = x - logncdf(x,p1,p2,'upper')/lognpdf(x,p1,p2);
I also tried with beta distribution, and got a similar error. How can I use logncdf
with symbolic variables?
matlab symbolic-math inverse
add a comment |
I need to find inverse of virtual value function of lognormal random variables. This is what I tried to do:
syms flogn(x,p1,p2)
% assume(p2<=0); %Adding this doesn't change the error
flogn(x,p1,p2) = x - logncdf(x,p1,p2,'upper')/lognpdf(x,p1,p2);
glogn = finverse(flogn,x);
But I got the error:
Error using symengine
Unable to prove 'p2 <= 0' literally. Use 'isAlways' to test the statement mathematically.
Error in sym/subsindex (line 810)
X = find(mupadmex('symobj::logical',A.s,9)) - 1;
Error in sym/privsubsasgn (line 1085)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',varargin),R_tilde);
Error in sym/subsasgn (line 922)
C = privsubsasgn(L,R,inds:);
Error in logncdf>locallogncdf (line 73)
sigma(sigma <= 0) = NaN;
Error in logncdf (line 47)
[varargout1:max(1,nargout)] = locallogncdf(uflag,x,varargin:);
Error in Untitled5 (line 3)
flogn(x,p1,p2) = x - logncdf(x,p1,p2,'upper')/lognpdf(x,p1,p2);
I also tried with beta distribution, and got a similar error. How can I use logncdf
with symbolic variables?
matlab symbolic-math inverse
This issue is similar to symbolic indexing.
– Bebs
Nov 21 '18 at 10:06
This issue is very similar to that one.
– Bebs
Nov 21 '18 at 11:12
add a comment |
I need to find inverse of virtual value function of lognormal random variables. This is what I tried to do:
syms flogn(x,p1,p2)
% assume(p2<=0); %Adding this doesn't change the error
flogn(x,p1,p2) = x - logncdf(x,p1,p2,'upper')/lognpdf(x,p1,p2);
glogn = finverse(flogn,x);
But I got the error:
Error using symengine
Unable to prove 'p2 <= 0' literally. Use 'isAlways' to test the statement mathematically.
Error in sym/subsindex (line 810)
X = find(mupadmex('symobj::logical',A.s,9)) - 1;
Error in sym/privsubsasgn (line 1085)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',varargin),R_tilde);
Error in sym/subsasgn (line 922)
C = privsubsasgn(L,R,inds:);
Error in logncdf>locallogncdf (line 73)
sigma(sigma <= 0) = NaN;
Error in logncdf (line 47)
[varargout1:max(1,nargout)] = locallogncdf(uflag,x,varargin:);
Error in Untitled5 (line 3)
flogn(x,p1,p2) = x - logncdf(x,p1,p2,'upper')/lognpdf(x,p1,p2);
I also tried with beta distribution, and got a similar error. How can I use logncdf
with symbolic variables?
matlab symbolic-math inverse
I need to find inverse of virtual value function of lognormal random variables. This is what I tried to do:
syms flogn(x,p1,p2)
% assume(p2<=0); %Adding this doesn't change the error
flogn(x,p1,p2) = x - logncdf(x,p1,p2,'upper')/lognpdf(x,p1,p2);
glogn = finverse(flogn,x);
But I got the error:
Error using symengine
Unable to prove 'p2 <= 0' literally. Use 'isAlways' to test the statement mathematically.
Error in sym/subsindex (line 810)
X = find(mupadmex('symobj::logical',A.s,9)) - 1;
Error in sym/privsubsasgn (line 1085)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',varargin),R_tilde);
Error in sym/subsasgn (line 922)
C = privsubsasgn(L,R,inds:);
Error in logncdf>locallogncdf (line 73)
sigma(sigma <= 0) = NaN;
Error in logncdf (line 47)
[varargout1:max(1,nargout)] = locallogncdf(uflag,x,varargin:);
Error in Untitled5 (line 3)
flogn(x,p1,p2) = x - logncdf(x,p1,p2,'upper')/lognpdf(x,p1,p2);
I also tried with beta distribution, and got a similar error. How can I use logncdf
with symbolic variables?
matlab symbolic-math inverse
matlab symbolic-math inverse
edited Nov 21 '18 at 10:43
Adriaan
12.5k63160
12.5k63160
asked Nov 12 '18 at 2:13
cauthon14
69211
69211
This issue is similar to symbolic indexing.
– Bebs
Nov 21 '18 at 10:06
This issue is very similar to that one.
– Bebs
Nov 21 '18 at 11:12
add a comment |
This issue is similar to symbolic indexing.
– Bebs
Nov 21 '18 at 10:06
This issue is very similar to that one.
– Bebs
Nov 21 '18 at 11:12
This issue is similar to symbolic indexing.
– Bebs
Nov 21 '18 at 10:06
This issue is similar to symbolic indexing.
– Bebs
Nov 21 '18 at 10:06
This issue is very similar to that one.
– Bebs
Nov 21 '18 at 11:12
This issue is very similar to that one.
– Bebs
Nov 21 '18 at 11:12
add a comment |
1 Answer
1
active
oldest
votes
Note that you could have minimalize your sample code even more, like this:
syms flogn(x,p1,p2)
flogn(x,p1,p2) = logncdf(x,p1,p2);
It's shorter, produces the same error and helps us to focus on the source of the error message.
So, the error doesn't come from trying to inverse a function, but from trying to use an existing function for numerical calculations with symbolic variables.
The error comes from the fact that you want to create a symbolic function flogn
based on existing function logncdf
, and logncdf
has a multiple comparisons.
With the command edit logncdf
, you can read the source code of the function and see comparison at lines 73 and 76.
% Return NaN for out of range parameters.
sigma(sigma <= 0) = NaN;
% Negative data would create complex values, which erfc cannot handle.
x(x < 0) = 0;
Matlab cannot compare symbols so it throws errors.
Depending on what you really need, you can have different solutions.
Do you really need to symbolize the function
flogn
? Couldn't you just write it as afunction
then calculate the inverse of it (if it can be inversed...)?If you really want to keep the symbolization, you can also rewrite your own function
logncdf
(with another name) so it does not have the comparisons. But it's still not guaranteed that you will find an inverse.
Thanks for the minimization suggestion. Will keep in mind the next time.
– cauthon14
Nov 21 '18 at 21:00
1
I don't need to symbolize the function. But how do I compute the inverse without it? For now, I have circumvented the problem, but I would still like to know your thoughts on this. Is creating an array X of numbers and then computing y = fzero(f(x)-x) on all x in X the only way?
– cauthon14
Nov 21 '18 at 21:13
@cauthon14 Hi! I would recommend usingfzero
just like you said. I suggest reading this or a lot of questions about similar topics have been ask here, in SO. If you still don't find a solution in existing questions in SO, fell free to ask a new question. Regards.
– Bebs
Nov 22 '18 at 7:47
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%2f53255204%2funable-to-prove-literally-error-when-trying-to-create-a-symbolic-function-base%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
Note that you could have minimalize your sample code even more, like this:
syms flogn(x,p1,p2)
flogn(x,p1,p2) = logncdf(x,p1,p2);
It's shorter, produces the same error and helps us to focus on the source of the error message.
So, the error doesn't come from trying to inverse a function, but from trying to use an existing function for numerical calculations with symbolic variables.
The error comes from the fact that you want to create a symbolic function flogn
based on existing function logncdf
, and logncdf
has a multiple comparisons.
With the command edit logncdf
, you can read the source code of the function and see comparison at lines 73 and 76.
% Return NaN for out of range parameters.
sigma(sigma <= 0) = NaN;
% Negative data would create complex values, which erfc cannot handle.
x(x < 0) = 0;
Matlab cannot compare symbols so it throws errors.
Depending on what you really need, you can have different solutions.
Do you really need to symbolize the function
flogn
? Couldn't you just write it as afunction
then calculate the inverse of it (if it can be inversed...)?If you really want to keep the symbolization, you can also rewrite your own function
logncdf
(with another name) so it does not have the comparisons. But it's still not guaranteed that you will find an inverse.
Thanks for the minimization suggestion. Will keep in mind the next time.
– cauthon14
Nov 21 '18 at 21:00
1
I don't need to symbolize the function. But how do I compute the inverse without it? For now, I have circumvented the problem, but I would still like to know your thoughts on this. Is creating an array X of numbers and then computing y = fzero(f(x)-x) on all x in X the only way?
– cauthon14
Nov 21 '18 at 21:13
@cauthon14 Hi! I would recommend usingfzero
just like you said. I suggest reading this or a lot of questions about similar topics have been ask here, in SO. If you still don't find a solution in existing questions in SO, fell free to ask a new question. Regards.
– Bebs
Nov 22 '18 at 7:47
add a comment |
Note that you could have minimalize your sample code even more, like this:
syms flogn(x,p1,p2)
flogn(x,p1,p2) = logncdf(x,p1,p2);
It's shorter, produces the same error and helps us to focus on the source of the error message.
So, the error doesn't come from trying to inverse a function, but from trying to use an existing function for numerical calculations with symbolic variables.
The error comes from the fact that you want to create a symbolic function flogn
based on existing function logncdf
, and logncdf
has a multiple comparisons.
With the command edit logncdf
, you can read the source code of the function and see comparison at lines 73 and 76.
% Return NaN for out of range parameters.
sigma(sigma <= 0) = NaN;
% Negative data would create complex values, which erfc cannot handle.
x(x < 0) = 0;
Matlab cannot compare symbols so it throws errors.
Depending on what you really need, you can have different solutions.
Do you really need to symbolize the function
flogn
? Couldn't you just write it as afunction
then calculate the inverse of it (if it can be inversed...)?If you really want to keep the symbolization, you can also rewrite your own function
logncdf
(with another name) so it does not have the comparisons. But it's still not guaranteed that you will find an inverse.
Thanks for the minimization suggestion. Will keep in mind the next time.
– cauthon14
Nov 21 '18 at 21:00
1
I don't need to symbolize the function. But how do I compute the inverse without it? For now, I have circumvented the problem, but I would still like to know your thoughts on this. Is creating an array X of numbers and then computing y = fzero(f(x)-x) on all x in X the only way?
– cauthon14
Nov 21 '18 at 21:13
@cauthon14 Hi! I would recommend usingfzero
just like you said. I suggest reading this or a lot of questions about similar topics have been ask here, in SO. If you still don't find a solution in existing questions in SO, fell free to ask a new question. Regards.
– Bebs
Nov 22 '18 at 7:47
add a comment |
Note that you could have minimalize your sample code even more, like this:
syms flogn(x,p1,p2)
flogn(x,p1,p2) = logncdf(x,p1,p2);
It's shorter, produces the same error and helps us to focus on the source of the error message.
So, the error doesn't come from trying to inverse a function, but from trying to use an existing function for numerical calculations with symbolic variables.
The error comes from the fact that you want to create a symbolic function flogn
based on existing function logncdf
, and logncdf
has a multiple comparisons.
With the command edit logncdf
, you can read the source code of the function and see comparison at lines 73 and 76.
% Return NaN for out of range parameters.
sigma(sigma <= 0) = NaN;
% Negative data would create complex values, which erfc cannot handle.
x(x < 0) = 0;
Matlab cannot compare symbols so it throws errors.
Depending on what you really need, you can have different solutions.
Do you really need to symbolize the function
flogn
? Couldn't you just write it as afunction
then calculate the inverse of it (if it can be inversed...)?If you really want to keep the symbolization, you can also rewrite your own function
logncdf
(with another name) so it does not have the comparisons. But it's still not guaranteed that you will find an inverse.
Note that you could have minimalize your sample code even more, like this:
syms flogn(x,p1,p2)
flogn(x,p1,p2) = logncdf(x,p1,p2);
It's shorter, produces the same error and helps us to focus on the source of the error message.
So, the error doesn't come from trying to inverse a function, but from trying to use an existing function for numerical calculations with symbolic variables.
The error comes from the fact that you want to create a symbolic function flogn
based on existing function logncdf
, and logncdf
has a multiple comparisons.
With the command edit logncdf
, you can read the source code of the function and see comparison at lines 73 and 76.
% Return NaN for out of range parameters.
sigma(sigma <= 0) = NaN;
% Negative data would create complex values, which erfc cannot handle.
x(x < 0) = 0;
Matlab cannot compare symbols so it throws errors.
Depending on what you really need, you can have different solutions.
Do you really need to symbolize the function
flogn
? Couldn't you just write it as afunction
then calculate the inverse of it (if it can be inversed...)?If you really want to keep the symbolization, you can also rewrite your own function
logncdf
(with another name) so it does not have the comparisons. But it's still not guaranteed that you will find an inverse.
edited Nov 21 '18 at 10:16
answered Nov 20 '18 at 9:25
Bebs
87631023
87631023
Thanks for the minimization suggestion. Will keep in mind the next time.
– cauthon14
Nov 21 '18 at 21:00
1
I don't need to symbolize the function. But how do I compute the inverse without it? For now, I have circumvented the problem, but I would still like to know your thoughts on this. Is creating an array X of numbers and then computing y = fzero(f(x)-x) on all x in X the only way?
– cauthon14
Nov 21 '18 at 21:13
@cauthon14 Hi! I would recommend usingfzero
just like you said. I suggest reading this or a lot of questions about similar topics have been ask here, in SO. If you still don't find a solution in existing questions in SO, fell free to ask a new question. Regards.
– Bebs
Nov 22 '18 at 7:47
add a comment |
Thanks for the minimization suggestion. Will keep in mind the next time.
– cauthon14
Nov 21 '18 at 21:00
1
I don't need to symbolize the function. But how do I compute the inverse without it? For now, I have circumvented the problem, but I would still like to know your thoughts on this. Is creating an array X of numbers and then computing y = fzero(f(x)-x) on all x in X the only way?
– cauthon14
Nov 21 '18 at 21:13
@cauthon14 Hi! I would recommend usingfzero
just like you said. I suggest reading this or a lot of questions about similar topics have been ask here, in SO. If you still don't find a solution in existing questions in SO, fell free to ask a new question. Regards.
– Bebs
Nov 22 '18 at 7:47
Thanks for the minimization suggestion. Will keep in mind the next time.
– cauthon14
Nov 21 '18 at 21:00
Thanks for the minimization suggestion. Will keep in mind the next time.
– cauthon14
Nov 21 '18 at 21:00
1
1
I don't need to symbolize the function. But how do I compute the inverse without it? For now, I have circumvented the problem, but I would still like to know your thoughts on this. Is creating an array X of numbers and then computing y = fzero(f(x)-x) on all x in X the only way?
– cauthon14
Nov 21 '18 at 21:13
I don't need to symbolize the function. But how do I compute the inverse without it? For now, I have circumvented the problem, but I would still like to know your thoughts on this. Is creating an array X of numbers and then computing y = fzero(f(x)-x) on all x in X the only way?
– cauthon14
Nov 21 '18 at 21:13
@cauthon14 Hi! I would recommend using
fzero
just like you said. I suggest reading this or a lot of questions about similar topics have been ask here, in SO. If you still don't find a solution in existing questions in SO, fell free to ask a new question. Regards.– Bebs
Nov 22 '18 at 7:47
@cauthon14 Hi! I would recommend using
fzero
just like you said. I suggest reading this or a lot of questions about similar topics have been ask here, in SO. If you still don't find a solution in existing questions in SO, fell free to ask a new question. Regards.– Bebs
Nov 22 '18 at 7:47
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53255204%2funable-to-prove-literally-error-when-trying-to-create-a-symbolic-function-base%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
This issue is similar to symbolic indexing.
– Bebs
Nov 21 '18 at 10:06
This issue is very similar to that one.
– Bebs
Nov 21 '18 at 11:12