saving . . . saved getting started with symbolics has been deleted. getting started with symbolics has been hidden .
getting started with symbolics
Title
Question
Dear All
I am using jupyter notebook in Python 3

On typing 

var('x')
h(x)=x^2
g(x)=x
f= Piecewise([[(0,1),h(x)],[(1,2),g(x)]],x)



I get following reply.

<pre style="overflow: auto; font-family: monospace; padding: 1px 0px; margin-bottom: 0px; line-height: inherit; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); border-width: 0px; border-style: initial; border-color: initial; vertical-align: baseline;"><span class="ansi-red-fg" style="color: rgb(231, 92, 88);">--------------------------------------------------------------------------</span> <span class="ansi-red-fg" style="color: rgb(231, 92, 88);">NameError</span> Traceback (most recent call last) <span class="ansi-green-fg" style="color: rgb(0, 162, 80);"><ipython-input-46-77057750395d></span> in <span class="ansi-cyan-fg" style="color: rgb(96, 198, 200);"><module></span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">()</span> <span class="ansi-green-intense-fg ansi-bold" style="color: rgb(0, 116, 39); font-weight: bold;"> 2</span> __tmp__<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">=</span>var<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">"x"</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">;</span> h <span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">=</span> symbolic_expression<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span>x<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">**</span>Integer<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span><span class="ansi-cyan-fg" style="color: rgb(96, 198, 200);">2</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">.</span>function<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span>x<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span> <span class="ansi-green-intense-fg ansi-bold" style="color: rgb(0, 116, 39); font-weight: bold;"> 3</span> __tmp__<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">=</span>var<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">"x"</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">;</span> g <span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">=</span> symbolic_expression<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span>x<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">.</span>function<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span>x<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span> <span class="ansi-green-fg" style="color: rgb(0, 162, 80);">----> 4</span><span class="ansi-red-fg" style="color: rgb(231, 92, 88);"> </span>f<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">=</span> Piecewise<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">[</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">[</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span>Integer<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span><span class="ansi-cyan-fg" style="color: rgb(96, 198, 200);">0</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">,</span>Integer<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span><span class="ansi-cyan-fg" style="color: rgb(96, 198, 200);">1</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">,</span>h<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span>x<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">]</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">,</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">[</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span>Integer<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span><span class="ansi-cyan-fg" style="color: rgb(96, 198, 200);">1</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">,</span>Integer<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span><span class="ansi-cyan-fg" style="color: rgb(96, 198, 200);">2</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">,</span>g<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">(</span>x<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">]</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">]</span><span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">,</span>x<span class="ansi-blue-fg" style="color: rgb(32, 143, 251);">)</span> <span class="ansi-red-fg" style="color: rgb(231, 92, 88);">NameError</span>: name 'Piecewise' is not defined </pre><pre style="overflow: auto; font-family: monospace; padding: 1px 0px; margin-bottom: 0px; line-height: inherit; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); border-width: 0px; border-style: initial; border-color: initial; vertical-align: baseline;">
</pre><pre style="overflow: auto; font-family: monospace; padding: 1px 0px; margin-bottom: 0px; line-height: inherit; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); border-width: 0px; border-style: initial; border-color: initial; vertical-align: baseline;">
</pre><pre style="overflow: auto; font-family: monospace; padding: 1px 0px; margin-bottom: 0px; line-height: inherit; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); border-width: 0px; border-style: initial; border-color: initial; vertical-align: baseline;">Kindly help</pre>


Python-3.4.3 Getting-Started-with-Functions 00-01 min 10-20 sec 27-04-20, 10:29 p.m. gaganj1981@gmail.com

Answers:

Try this

f = piecewise([[(0,1),h(x)],[(1,2),g(x)]],x)
28-04-20, 12:45 a.m. iakashchavan


Log-in to answer to this question.