Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5799
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: strange error |
| Date | 2011-10-23 10:24 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j80q12$a9o$1@smc.vnet.net> (permalink) |
| References | <201110221009.GAA29789@smc.vnet.net> |
Here are three versions that work:
test1[m_?NumericQ] := Module[{ret},
If[m < 100, ret = 2 m];
If[100 <= m <= 200, ret = 200 + (m - 100)];
If[200 < m, ret = 300 + 0.5 (m - 200)];
N@ret
]
test2[m_] =
Piecewise[{{2 m, m < 100}, {200 + (m - 100),
100 <= m <= 200}, {300 + 0.5 (m - 200), 200 < m}}];
test3[m_] = Which[m < 100, 2 m,
100 <= m <= 200, 200 + (m - 100),
200 < m, 300 + 0.5 (m - 200),
True, 0];
FindRoot[test1@m == 250, {m, 150, 0, 300}]
FindRoot[test2@m == 250, {m, 150, 0, 300}]
FindRoot[test3@m == 250, {m, 150, 0, 300}]
{m -> 150.}
{m -> 150.}
{m -> 150.}
The original style is a very bad habit.
Bobby
On Sat, 22 Oct 2011 05:09:04 -0500, Klemen Dovrtel
<klemen_dovrtel@yahoo.com> wrote:
> Hello everybody,
>
> I defined a simple function that is composed of three functions, each
> for different range of argument/variable. The function was composed
> using If[] conditions. The problem is that i can't FindRoot of this
> composed function. I get an error "the function value is not a list of
> numbers with dimensions {1}", which is not true. Any idea how can i
> solve this?
>
>
> Mathematica print screen:
>
> http://www.shrani.si/f/t/vo/3jLzgMiy/prtscr.jpg
>
> Best Regards
> Klemen
--
DrMajorBob@yahoo.com
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: strange error DrMajorBob <btreat1@austin.rr.com> - 2011-10-23 10:24 +0000
csiph-web