Piecewise Function Plot: Program 1
Piecewise Function
Plot a piecewise function where:
\[ f(x) = \begin{cases} x^2 & \text{if } x > 0 \\ x & \text{otherwise} \end{cases} \]
Output 1
Unary Operators
| Symbol | Example | Explanation |
|---|---|---|
| - | \(-a\) | unary minus |
| + | \(+a\) | unary plus (no-operation) |
| ~ | \(~a\) | one's complement |
| ! | \(!a\) | logical negation |
| ! | \(a!\) | factorial |
| $ | \($3\) | call arg/column during 'using' manipulation |
| \(|\) | \(|A|\) | cardinality of array \( A \) |
Binary Operators
| Symbol | Example | Explanation |
|---|---|---|
| ** | a**b | exponentiation |
| * | a*b | multiplication |
| / | a/b | division |
| % | a%b | modulo |
| + | a+b | addition |
| - | a-b | subtraction |
| == | a==b | equality |
| != | a!=b | inequality |
| < | a | less than |
| <= | a<=b | less than or equal to |
| > | a>b | greater than |
| >= | a>=b | greater than or equal to |
| << | 0xff<<1 | left shift unsigned |
| >> | 0xff>>1 | right shift unsigned |
| & | a&b | bitwise AND |
| ^ | a^b | bitwise exclusive OR |
| | | a|b | bitwise inclusive OR |
| && | a&&b | logical AND |
| || | a||b | logical OR |
| = | a=b | assignment |
| , | (a,b) | serial evaluation |
| . | A.B | string concatenation |
| eq | A eq B | string equality |
| ne | A ne B | string inequality |
Ternary Operator
| Symbol | Example | Explanation |
|---|---|---|
$$\text{?}:\text{}$$ |
$$\text{a ? b : c}$$ |
$$\text{ternary operation}$$ |
Piecewise Function Plot: Program 2
Plot a piecewise function where:
\[ f(x) = \begin{cases} 5x & \text{if } x < -3 \\ -5x & \text{if } x > 3 \\ x & \text{otherwise} \end{cases} \]
Output 2
Piecewise Function Plot: Program 3
Plot a piecewise function where:
\[ f(x) = \begin{cases} x^2 & \text{if } x \geq 2 \\ x & \text{if } -1 \leq x < 2 \\ -1 & \text{otherwise} \end{cases} \]
Output 3
Piecewise Function Plot: Program 4
Plot a piecewise function where:
\[ f(x) = \begin{cases} \frac{x^2}{x} for \quad x \neq 0 \\ undefined (NaN) \quad at \quad x = 0 \\ \end{cases} \]
Output 4
Piecewise Function Plot: Program 5
Plot the following piecewise function:
\[ f(x) = \begin{cases} 0 & \text{if } x < -1 \text{ or } x > 1 \\ x & \text{if } -1 \leq x \leq 1 \end{cases} \]
Output 5
Piecewise Function Plot: Program 6
Three functions are defined in the given range as follows:
Plot the three functions using GNUPLOT.
Output 6
Piecewise Function Plot: Program 7
Plot the following functions for \(0 \le x \le \pi\) on the same graph using GNUPLOT. Set 1000 samples. Mark each curve with different line style and line widths.
\(f_1(x) = \sin^2(\sqrt{x})\)
\(f_2(x) = e^{-x/2} \cos(2\pi x)\)
\(f_3(x) = 12.34x^{5/3}\)