hpierce
hpierce

Reputation: 1

Plotting a Parametric Curve in MatLab with a Double

I am trying to plot the parametric equation (t, -4, t^2 + 17), but am running into difficulties. I have been trying

fplot3(t, -4, t.^2+17)

But am getting the following error: Undefined function 'fplot3' for input arguments of type 'double'.

Any help is greatly appreciated!

Upvotes: 0

Views: 665

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112699

fplot3 expects anonymous functions as inputs. So, you can use

fplot3(@(t) t,  @(t) -4,  @(t) t.^2+17)

Note the use of .^, which is element-wise power.

The above works, but gives a warning

Warning: Function fails on array inputs. Use element-wise operators to increase speed.

The reason is that the second function outputs a scalar, instead of an array the same size as the input t. To solve this, replace that function as follows:

fplot3(@(t) t,  @(t) repmat(-4, size(t)),  @(t) t.^2+17)

Also, you can specify the range of t as a fourth input:

fplot3(@(t) t,  @(t) repmat(-4, size(t)),  @(t) t.^2+17,  [-10 10])

enter image description here

Upvotes: 2

Related Questions