How can I store an equation as a variable?
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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)
0 commentaires
Réponse acceptée
Paulo Silva
le 22 Jan 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 commentaires
Paulo Silva
le 22 Jan 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 :)
Plus de réponses (1)
Walter Roberson
le 22 Jan 2011
You can also use symbolic variables if you have the Symbolic Toolbox.
0 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!