How to use a variable in the piecewise command

We're glad you came by, but you might find what you're looking for elsewhere.

TI-Basic Developer is not the site it once was. While its information on commands and other calculator features remains almost second-to-none, its forum, archives, and even hosting service, Wikidot, have been decaying for years. The calculator community would love to see what you're working on, or help you in your next coding adventure, but TI-Basic Developer is no longer the place to do it.

Instead, you should head over to Cemetech (primarily American) or TI-Planet (primarily international). Both are active, well-established forums with their own archives, chatrooms, reference material, and abundant coding tools and resources. We'll see you there, we hope.

Forum » Programming & Design / CE and CSE Programming » How to use a variable in the piecewise command
Started by: ProfLisa ProfLisa
Date: 06 Jan 2020 20:20
Number of posts: 9
rss icon RSS: New posts
How to use a variable in the piecewise command
ProfLisa ProfLisa 06 Jan 2020 20:20

I am writing a program that would allow the user to input two functions and two intervals and then graph the piecewise defined function.

:"piecewise(Y1, X≤0, Y2,X>0)"→Y3
:DispGraph

works fine but I would like to replace the "X≤0" and "X>0" with string inputs. However this results in a data type error. Any suggestions?

by ProfLisa ProfLisa , 06 Jan 2020 20:20
Re: How to use a variable in the piecewise command
Trenly Trenly 06 Jan 2020 21:03

—Thread Moved

The piecewise( command page shows how to do this in its first section of code

by Trenly Trenly , 06 Jan 2020 21:03
Re: How to use a variable in the piecewise command
ProfLisa ProfLisa 07 Jan 2020 17:25

The first piece of code is
piecewise(Y1,X≥0,Y2,X<0→Y3

This shows the conditions as being hard-coded values, not variables. I would like to do this:
piecewise(Y1,Str1,Y2,Str2)

I'm not sure you read my post completely.

Last edited on 07 Jan 2020 17:26 by ProfLisa
by ProfLisa ProfLisa , 07 Jan 2020 17:25
Re: How to use a variable in the piecewise command
Trenly Trenly 07 Jan 2020 20:02

You could try string concatenation

"piecewise(Y1,"+Str1+",Y2,"+Str2→Y3

by Trenly Trenly , 07 Jan 2020 20:02
Re: How to use a variable in the piecewise command
ProfLisa ProfLisa 09 Jan 2020 00:43

Yes, this worked, thank you!

by ProfLisa ProfLisa , 09 Jan 2020 00:43
Re: How to use a variable in the piecewise command
QubicQuantum QubicQuantum 12 Jan 2020 02:47

wouldn't you need a Str>Expr command?

by QubicQuantum QubicQuantum , 12 Jan 2020 02:47
Re: How to use a variable in the piecewise command
Trenly Trenly 12 Jan 2020 06:02

Not for the piecewise( command. The CE and CSE are a little different than the 83/34/+/SE

by Trenly Trenly , 12 Jan 2020 06:02
Re: How to use a variable in the piecewise command
Myles_Zadok Myles_Zadok 08 Jan 2020 04:39

I would try Trenly Trenly 's suggestion, but I don't think that will work (please let me know if it does in fact work), because conditionals are a mixture of variables and conditional operators. The calculator does not seem to read the expressions the way it reads a string. The only work around I can think of would be to use a menu(s) to give the user the ability to select the desired conditional parameters.

by Myles_Zadok Myles_Zadok , 08 Jan 2020 04:39
Re: How to use a variable in the piecewise command
Trenly Trenly 08 Jan 2020 04:55

I'm doubtful it will work either, but looking at the example code on the command page, it looks like it is just storing a string into Y3, which is why I thought that concatenation may do the trick

by Trenly Trenly , 08 Jan 2020 04:55
/forum/t-12909016/how-to-use-a-variable-in-the-piecewise-command#post-
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).
Notify administrators if there is objectionable content in this page.
Something does not work as expected? Find out what you can do.
General Wikidot.com documentation and help section.
Wikidot.com Terms of Service - what you can, what you should not etc.
Wikidot.com Privacy Policy.

AltStyle によって変換されたページ (->オリジナル) /