RE: Beginner--Simplest question: How to control some values in Input dialog box
- To: mathgroup at smc.vnet.net
- Subject: [mg67760] RE: [mg67715] Beginner--Simplest question: How to control some values in Input dialog box
- From: "David Park" <djmp at earthlink.net>
- Date: Thu, 6 Jul 2006 06:54:16 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Instead of using the Input Dialog, why not do something like this...
SetMyParameters::badCN = "CN must be a positive integer. You entered ``";
SetMyParameters::badc = "You must have 0 < c < 0.9. You entered ``";
SetMyParameters[CNin_, cin_] :=
Module[{gooddata = True},
Clear[CN, c];
If[¬ (IntegerQ[CNin] \[And] CNin > 0),
Message[SetMyParameters::badCN, CNin]; gooddata = False];
If[¬ 0 < cin < 0.9, Message[SetMyParameters::badc, cin];
gooddata = False];
If[gooddata, CN = CNin; c = cin;]
]
SetMyParameters[-1, -3]
{CN, c} gives
SetMyParameters::badCN: CN must be a positive integer. You entered -1
SetMyParameters::badc: You must have 0 < c < 0.9. You entered -3
{CN, c}
SetMyParameters[3, 0.7]
{CN, c} gives
{3, 0.7}
But I would hesitate to set values for quantities like CN and c. Why not
build them as conditional parameters into your function definition? For
example...
function[CN_Integer?Positive, c_ /; 0 < c < 0.9][x_] := (x + c)^CN
function[-1, -3][x] won't evaluate
function[-1, -3][x]
function[3, 0.7][x] evaluates
(0.7 + x)^3
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
From: abdou.oumaima at hotmail.com [mailto:abdou.oumaima at hotmail.com]
To: mathgroup at smc.vnet.net
Hi mathematica users,
In the begining of my program, I've to initialize some parametres. I would
like to do some control on them.
I put:
CN= Input["Give an positive integer value to CN"];
c= Input["Give a positive real value to c less than 0.9"]
How to control the values CN and c so that they verify my conditions in the
message box?
Any help please.
Thank you for all of you
Link to the forum page for this post:
http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Speci
al:Forum_ViewTopic&pid=11670#p11670
Posted through http://www.mathematica-users.org [[postId=11670]]