How can I store an equation as a variable?

17 visualizaciones (últimos 30 días)
Greg
Greg el 22 de En. de 2011
I've made a function that determines the parametric equation for a line in 3D. But now I want to plot that line using plot3. I'd like to just store the equation in one place so it's easy to access for plot3. For example I'd like to be able to do the following:
XT = t/4 + 3
YT = 3t/2 - 8
ZT = 1
plot3(XT, YT, ZT)
However, it doesn't want to store unknown variables like t in these equations. What can I do to make this work? Thanks for your time. (P.S. First time using matlab answers and I'm pretty sure I used the markup stuff wrong)

Respuesta aceptada

Paulo Silva
Paulo Silva el 22 de En. de 2011
%create the functions
XT=inline('t./4+3')
YT=inline('3*t./2-8')
ZT=inline('t')
%for example if you want to plot them easily do
ezplot(XT,-1,2) %in this case -1 is lower t and 2 is the higher t value
%if you want to convert from inline to string do
char(XT)
%example
XT=inline('t./4+3');
YT=inline('3*t./2-8');
ZT=inline('1+0*t'); %it refuses to work with just ZT=inline('1');
t=0:0.1:100;
plot3(XT(t),YT(t),ZT(t));
%Answer edited because it had mistakes (/->./ and ->.) and example added
  5 comentarios
Greg
Greg el 22 de En. de 2011
Fantastic. Thanks much.
Paulo Silva
Paulo Silva el 22 de En. de 2011
My pleasure, if you have any other question be free to post it, we like to help, at least in my case it helps me remember important things about matlab :)

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 22 de En. de 2011
You can also use symbolic variables if you have the Symbolic Toolbox.

Categorías

Más información sobre Programming en Help Center 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