# Plot hermite spline [closed]

I'm new to Mathematica and cannot figure out a way to plot a 2d hermite spline. My points are: $p_0=\{143.05;195.606\};$ $p_1=\{159.373;181.845\};$ $p_2=\{160.891;179.26\};$ $p_3=\{176.423;171.878\};$

I need to plot the spline from $p_0$ to $p_1$

I calculate Catmull-Rom tangents in the following way: $\left(t_1=0.5 \left(p_2-p_0\right);\right)$ $\left(t_2=0.5 \left(p_3-p_1\right);\right)$

Calculating the weights: $$\left(h_1(\text{t\_})\text{:=}2 t^3-3 t^2+1;\right) \left(h_2(\text{t\_})\text{:=}3 t^2-2 t^3;\right) \left(h_3(\text{t\_})\text{:=}t^3-2 t^2+t;\right) \left(h_4(\text{t\_})\text{:=}t^3-t^2;\right)$$

And finaly the spline function: $$P(\text{t\_})\text{:=}\left\{h_1 p_1.x+h_2 p_2.x+h_3 t_1.x+4 h_4 t_2.x;h_1 p_1.y+h_2 p_2.y+h_3 t_1.y+4 h_4 t_2.y\right\};$$

And trying to plot it: $$\text{ParametricPlot}[\{P(t)\},\{t,0,1\}]$$

But I'm getting some strange errors:

SetDelayed::write: Tag Plus in (1-3 t^2+2 t^3)[t_] is Protected. >>


What does it mean? Please provide me with a complete solution to plotting a hermite spline. Thanks!

UPDATE: My mathematica code is:

Subscript[p, 0] = {143.0497; 195.6056};
Subscript[p, 1] = {159.3734; 181.8449};
Subscript[p, 2] = {160.8912; 179.2604};
Subscript[p, 3] = {176.423; 171.8781};

Subscript[t, 1] = (Subscript[p, 2] - Subscript[p, 0]) * 0.5;
Subscript[t, 2] = (Subscript[p, 3] - Subscript[p, 1]) * 0.5;

Subscript[h, 1][t_] := 2 * t^3 - 3*t^2 + 1;
Subscript[h, 2][t_] := -2*t^3 + 3*t^2;
Subscript[h, 3][t_] := t^3 - 2*t^2 + t;
Subscript[h, 4][t_] := t^3 - t^2;

P[t_] := {Subscript[h, 1][t] * Subscript[p, 1].x +
Subscript[h, 2][t] * Subscript[p, 2].x +
Subscript[h, 3][t] * Subscript[t, 1].x +
Subscript[h, 4] [t]* Subscript[t, 2].x;
Subscript[h, 1][t] * Subscript[p, 1].y +
Subscript[h, 2][t] * Subscript[p, 2].y +
Subscript[h, 3][t] * Subscript[t, 1].y +
Subscript[h, 4][t] * Subscript[t, 2].y};

ParametricPlot[{P[t]}, {t, 0, 1}]

-

## closed as off-topic by Sjoerd C. de Vries, Artes, m_goldberg, rm -rf♦Oct 26 '13 at 14:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Sjoerd C. de Vries, Artes, m_goldberg, rm -rf
If this question can be reworded to fit the rules in the help center, please edit the question.

Hello Ilya:) Please post the actual Mathematica code instead of LateX form. –  Kuba Oct 26 '13 at 8:34
@Kuba please take a look at the code I posted. Thanks a lot! –  Ilya Suzdalnitski Oct 26 '13 at 8:55
What is x inside the definition of P[t]? Also you probably need to put there Subscript[h, 1][t] etc. instead of Subscript[h, 1] alone. –  Kuba Oct 26 '13 at 9:00
Since you're new to Mathematica, here's a piece of advise, refrain from using subscripts. –  RunnyKine Oct 26 '13 at 9:06
The Dot or . is the operator for the inner product of vectors. It is not an operator to obtain elements from a struct or an object, like it is in some other languages. If you want to get pieces of lists there are dedicated functions for that. –  Sjoerd C. de Vries Oct 26 '13 at 11:20

As already mentioned in the comments, you shouldn't be using subscripts. You can find more about that here.

There are a number of additional issues. Using ; as list separator, misuse of the . operator, and not using Mathematica's vector capabilities.

A direct conversion of your code would be:

p0 = {143.0497, 195.6056};
p1 = {159.3734, 181.8449};
p2 = {160.8912, 179.2604};
p3 = {176.423, 171.8781};

t1 = (p2 - p0)*0.5;
t2 = (p3 - p1)*0.5;

h1[t_] := 2*t^3 - 3*t^2 + 1;
h2[t_] := -2*t^3 + 3*t^2;
h3[t_] := t^3 - 2*t^2 + t;
h4[t_] := t^3 - t^2;

P[t_] := {h1[t] p1[[1]] + h2[t] p2[[1]] + h3[t] t1[[1]] + h4[t] t2[[1]],
h1[t] p1[[2]] + h2[t] p2[[2]] + h3[t]*t1[[2]] + h4[t] t2[[2]]};

ParametricPlot[P[t], {t, 0, 1}]


Using vectors instead of vector components, P could be written much shorter and clearer:

P[t_] := h1[t] p1 + h2[t] p2 + h3[t] t1 + h4[t] t2;

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 1, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.334550678730011, "perplexity": 7413.1652884695595}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-41/segments/1410657139314.4/warc/CC-MAIN-20140914011219-00119-ip-10-234-18-248.ec2.internal.warc.gz"}