Plotting a 3-D parametric curve (x,y,z) using different functions for x, y and z for different t values.
Mostrar comentarios más antiguos
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
Más respuestas (1)
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
Joseph Maylor
el 14 de En. de 2013
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
Categorías
Más información sobre Vector Fields en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!