How to plot three variables in matlab?? A*cos(w*t+theta)

4 次查看(过去 30 天)
Hello, i would like to plot A*cos(w*t+theta), when A, w and theta are symbolic variables (syms A,w,theta)
Is it possible to plot A*cos(w*t+theta) in matlab??

采纳的回答

John D'Errico
John D'Errico 2021-10-1
编辑:John D'Errico 2021-10-1
It certainly is possible. All you need is a multi-dimensional holographic monitor to view it. Sadly, these are hard to come by, and too often break down. In fact mine is under repair right now, as they still awaiting parts to be delivered from Borg manufacturing. Starfleet command is slow also, so we had the Borg drop-ship them.
Seriously, You want to plot a function of THREE variables, so you want to visualize a 5th variable, as a function of the other 4. In this case, it would be
Z = A*cos(w*t+theta)
Note that a plot displays only TWO dimensions, so even when you make a 3-d plot, you are only seeing a projected view into the plane of the plot. And that means to be able to understand a 3-d plot, you often need to rotate it around, to see it from multiple angles. Sometimes stereoscopic images can be made to work, but these often require the user to use either special glasses, or be able to cross their eyes.
[X,Y] = meshgrid(linspace(-pi,pi));
Z = sin(X + Y) - cos(X.*Y);
surf(X,Y,Z)
xlabel X
ylabel Y
zlabel Z
grid on
box on
And you may think that this shows you the surface, but to fully visualize what is happening, I often find it useful to rotate that surface, viewing it from many different angles. I'll pick some random view next:
surf(X,Y,Z)
xlabel X
ylabel Y
zlabel Z
grid on
box on
view(10,45)
You may even have been happy with the first figure. Again though, you need to recognize that ANY plot is just a projection into two dimensions. In fact, there are many illusions one can find of 3-d objects that can be misinterpreted when viewed as a2-d projection. Or, consider any M.C. Escher print, to understand that 2-dimensional "pictures" can be confusing, as the mind tries to interpret them in 3-d.
The problem is, this becomes far more difficult when you have some higher dimensional thing. For example, can you visualize the shape of a 4 or 5-dimenional hyper cube, when displayed as it is projected into a 2-d plane? Most people will fail to do so. (Do I really need to do that? Maybe I'll take a shot at it...)
The thing is, your mind works in 3-dimensions. (Have you read the book Flatland, by Edwin Abbott?)'
I would highly recommend it, if you have not.
In the end, you need to understand that even if you had a multi-dimensional holographic monitor, your mind would have serious difficulties in visualizing some high dimensional thing. Ok, just for kicks...
% generate a 5-dimensional unit hyper-cube. A 5-cube.
% The vertices of such a 5-cube are easy to generate, as the rows of the matrix C5
C5 = dec2bin(0:31) - '0'
C5 = 32×5
0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 0 1 0 0 1
% but how will we plot that using plot? A simple projection into 2
% dimensions will help. I'll pick one randomly, as:
proj = orth(randn(5,2))
proj = 5×2
-0.6305 0.1048 0.3826 -0.6957 0.3283 -0.2090 0.4938 0.5664 0.3233 0.3747
% and now the projection into 2-d is nothing more than a matrix multiplication.
C5_2 = C5*proj;
plot(C5_2(:,1),C5_2(:,2),'o')
Does that help? Is that clearly a 5-cube? Even if I made the effort to connect all the edges of that 5-cube, and then plot them, I doubt it would allow you to visualize that thing as obviously a unit 5-cube. Ugh. I probably can. But do I need to? Would it help? I think I am digressing.
The point of all this is your head cannot visualize the things you are asking to plot.
At best, you can use tools like an iso-surface, which is the equivalent of a contour plot, but for a 4-dimensional object. In your case however, you really have a 5-dimensional thing.
Or, you can fix TWO of the variables. Essentially, this is just a variation of a projection. So we might do this:
syms w t
theta = pi/3;
A = 1;
fsurf(A*cos(w*t + theta))
xlabel t
ylabel w
zlabel Z
title 'A = 1, theta = pi/3'
As you can see, even that simple surface is a complex thing to visualize, but I fixed TWO of the parameters, allowing only t and w to vary. Had I tried to show the behavior with the other two parameters, things would be more complex yet. Luckily, if you understand how those parameters enter into the prob lem, you can still visualize what they would do. But that only applies in certain problems.
Well, at least, until I get those parts from Borg delivery services. The problem is, when the Borg deliver, they often try to assimilate the entire planet, and I hate when that happens. But wait, I hear the doorbell ringing now..............

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by