Plotting a 3-D parametric curve (x,y,z) using different functions for x, y and z for different t values.

What I've done here is split up a curve into sections and defined each of the sections through different functions.
I know how to plot a 3-D parametric curve using different t functions for x, y and z. So for my first section I have used the following:
>> t = linspace(0,pi); >> x = t; >> y = 3*t; >> z = 2*pi + 0*t; >> plot3(x,y,z)
This creates the first section of my curve. Now I want to change the function that defines y for the t values from pi to 2pi.
i.e. for t = linspace(pi,2*pi), I want to change y = 3*pi + sin(t-pi)
Can anyone show me how to do this? Also, eventually I want to plot all the different sections onto 1 set of axes.
On a side note, when I enter "y = 3*pi - 3(t-2*pi);", I am confronted with: | Error: Unbalanced or unexpected parenthesis or bracket. Why?
Thanks for any help

 Respuesta aceptada

I rewrote Matt's example to make the idea more explicit; the first part in each line of the funy function selects the range and the second part implements the specific function for this interval.
funx = @(t) t;
funy = @(t) (t > 0 & t <= pi) .*3*t +...
(t > pi & t <= 2*pi).*(3*pi + sin(t - pi)) + ...
(t > 2*pi & t <= 3*pi).*(5*pi + cos(t - pi));
funz = @(t) 2*pi;
ezplot3(funx, funy, funz, [0, 3*pi])

Más respuestas (1)

Matt J
Matt J el 14 de En. de 2013
Editada: Matt J el 14 de En. de 2013
funx = @(t) t;
funy = @(t) (abs(t-pi/2)<=pi/2).*3.*t + (t>pi)*(3*pi + sin(t-pi));
funz = @(t) 2*pi;
ezplot3(funx,funy,funz,[0,2*pi])
On a side note, when I enter "y = 3*pi - 3(t-2*pi);", I am confronted with: | Error: Unbalanced or unexpected parenthesis or bracket. Why?
y = 3*pi - 3*(t-2*pi)

2 comentarios

Thanks for your help! That works great. Now say for the next 'section' (t from 2*pi to 3*pi), I wanted to change funy to (3*pi-3*(t-2*pi)), how would this look?
If I can see what that likes I should be able to do the rest. 7 sections in total so I want ask you to do all of them...
If you understand how the 2-piece example works, there is nothing really to tell about how to add additional pieces. Note that funx,y,z don't have to be anonymous functions. You can also pass handles to regular functions as well if that's easier to write
funy=@func
function z=func(t)
if t>0 & t<pi
elseif t>pi & t<...
elseif ...
end

Iniciar sesión para comentar.

Categorías

Más información sobre Vector Fields en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by