I wrote this code:

ClearAll[t]

n = 4;

t[0] = 0;

t[n] = 1;

h = N[(t[n] – t[0])/n, 2];

Do[t[L + 1] = t[L] + h;, {L, 0, n – 1}]

A[0][t_] :=

Piecewise[{{1 – (t – t[0])/(t[1] – t[0]), t[0] <= t <= t[1]}}]
A[k_][t_] :=
Piecewise[{{(t - t[k - 1])/(t[k] - t[k - 1]),
t[k - 1] <= t <= t[k]}, {1 - (t - t[k])/(t[k + 1] - t[k]),
t[k] <= t <= t[k + 1]}}];
A[n][t_] :=
Piecewise[{{(t - t[n - 1])/(t[n] - t[n - 1]),
t[n - 1] <= t <= t[n]}}];
Plot[Evaluate[A[#][t] & /@ Range[0, n]], {t, 0, 1},
PlotRange -> {0, 1}, PlotLegends -> “Expressions”]

I want to have scale in distance for Piecewise, for example in the following picture

=================

Assuming you want to add ticks at the indicated places, use the option Ticks -> {t /@ Range[0, n], Automatic}

– kglr

Apr 25 at 16:54

Many many thanks.

– bahram

Apr 25 at 17:00

=================

2 Answers

2

=================

Changed h = N[(t[n] – t[0])/n, 2]; to h = (t[n] – t[0])/n;

Changed Piecewise[…] to Simplify@Piecewise[…], and

Used t /@ Range[0, n] as horizontal axis ticks:

With these changes:

Plot[Evaluate[A[#][t] & /@ Range[0, n]], {t, 0, 1},

PlotRange -> {0, 1}, PlotLegends -> “Expressions”,

Ticks -> {t /@ Range[0, n], Automatic}]

Use Ticks -> {{#, N[#, 2]} & /@ t /@ Range[0, n], Automatic} if you want tick labels as decimal numbers.

Without the change in the definition of h we get:

Many thanks, but I use this code:` Plot[Evaluate[A[#][t] & /@ Range[0, n]], {t, 0, 1}, PlotRange -> {0, 1}, PlotLegends -> “Expressions”, Ticks -> {{#, N[#, 3]} & /@ t /@ Range[0, n]}] ` and I do not have decimal numbers in PlotLegends.

– user37694

Apr 27 at 8:27

@user37694, it could be due to version difference; i am using v9.

– kglr

Apr 27 at 8:36

I am using v10.

– user37694

Apr 29 at 13:20

Have a look at AxesOrigin and FindDivisions

Plot[Evaluate[A[#][t] & /@ Range[0, n]]

, {t, 0, 1}

, PlotRange -> {{-.25, 1.22}, {-.25, 1.25}}

, AxesOrigin -> {-.25, -.25}

, Ticks -> {FindDivisions[{0, 1}, 4], Automatic}

, PlotLegends -> “Expressions”]