Hi everyone. I would like to produce a graph like the one shown in the picture on MatLAB. Any help with writing the script will be greatly appreciated. The radius of each band increases from the central point 0,0.

 채택된 답변

Star Strider
Star Strider 2016년 2월 10일

1 개 추천

One possibility:
w = linspace(0, 2*pi);
c = [cos(w); sin(w)];
r = [1 2 3];
figure(1)
plot(r(1)*c(1,:), r(1)*c(2,:))
hold on
plot(r(2)*c(1,:), r(2)*c(2,:))
plot(r(3)*c(1,:), r(3)*c(2,:))
hold off
axis equal

댓글 수: 5

Ogen
Ogen 2016년 2월 10일
Hi Star Strider, thank you for the prompt reply. That is the type of graph I am looking for, however how will I change the distance between the bands.
For example if I wanted the second and third band to be closer together so a greater radius but the first band remain.
Thanks again
Star Strider
Star Strider 2016년 2월 10일
My pleasure.
To change the radii of the circles, change the values in my ‘r’ vector. For example, to put the second and third closer together:
r = [1 2 2.3];
You can make the values in ‘r’ whatever you want. To change the other characteristics of the circles (line widths, colours, and other properties), see the documentation for the plot function.
Ogen
Ogen 2016년 2월 10일
Thanks again. I have another question you may be able to help me with. This is part of a maths project investigating the height of a mushroom cloud. I want to plot a 3-D graph, displaying the height and radius at it's peak. The height will depend on the cause but I need a script that produces a graph to display this in 3 dimensions and allows me to change the inputted height variable.
Ogen
Ogen 2016년 2월 10일
Furthermore, would it be possible to explain the equation used for the first section so I understand the maths? Thanks
Star Strider
Star Strider 2016년 2월 10일
My pleasure.
The mushroom cloud problem would seem to be a computational fluid dynamics problem far beyond the scope of my knowledge. However, if you want to plot a cone plotting the radius at different heights, and perhaps the shape of the cloud itself, I would investigate the cylinder function. It, possibly in combination with the sphere function, could give you the result you want. This code uses both:
[Xc,Yc,Zc] = cylinder(0.5, 20);
[Xs,Ys,Zs] = sphere(20);
Xsm = Xs * 2;
Ysm = Ys * 2;
Zsm = Zs + 2;
figure(1)
surf(Xc,Yc,Zc)
hold on
surf(Xsm,Ysm,Zsm)
hold off
grid on
axis equal
view([-35 20])
to produce:

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Ogen
Ogen 2016년 2월 10일

0 개 추천

Wow that does sound complicated! I like the look of the graph you have plotted so I will definitely have a more detailed look. Your help is very much appreciated and helped to kick start my project, cheers.

댓글 수: 5

Star Strider
Star Strider 2016년 2월 10일
It is complicated, with rapid convection and all the rest of the atmospheric physics involved. I’m not certain what you want, so I’ll leave the web search to you. The same sort of physics might apply to the rapid development of a thunderstorm, so there are likely articles on the Internet that you could implement in MATLAB that would give you the behaviour you want to model. I imagine it would involve solving partial differential equations in time and distance, but there could be published solutions for you to use.
My plot is simply a way to create the image. You can easily experiment with my code to make it look the way you want, and also to animate it. See the documentation on Vector Fields and Surfaces, Volumes, and Polygons, particularly the section on Volume Visualization for more plotting options.
When you get your project coded and working, write it up and submit it as a File Exchange contribution. It seems to me to be something that atmospheric physicists and other fluid dynamicists would be interested in.
Cheers — and good luck! We’ll help you here as we can!
Ogen
Ogen 2016년 3월 6일
Hello again Star Strider, thanks for your previous help. With so some modification the mushroom cloud now looks very good and the rings graph does the job perfectly. Do you know how to turn these plots into animated graphs? So the rings graph makes ripples like throwing a stone in a puddle of water. And the mushroom cloud appears like in real life so raises from the bottom, growing in height. I have seen examples on the rippling water effect but I am struggling to implement the code into my graph scripts. Any help with these two problems would be greatly appreciated.
Star Strider
Star Strider 2016년 3월 6일
I’m glad you got it working! Consider contributing it to the File Exchange when you get it to the point you’re happy with it, and have the time to document it and make it into a funciton.
As for the movie, there are at least a couple ways of doing that. Two relevant functions are drawnow and getframe. Those (and their friends) should allow you to do what you want, although by different approaches.
Ogen
Ogen 2016년 3월 6일
Thanks for the reply. Would my code be able to be created into an animation plot using the drawnow and getframe functions as I have tried and I can't seem to crack it.
Star Strider
Star Strider 2016년 3월 6일
My pleasure.
The drawnow function is useful inside a loop, so that you calculate and draw each frame and animate it in real time. This works best if the calculations creating the image are reasonably fast, and the resolution relatively low.
The getframe function and its friends allow you to create a movie out of your MATLAB images. This is best if the calculations for each frame take a while, are relatively high resolution, and so are not suited to real time display. If you have detailed images that take some time to render and you don’t need to change the parameters of the simulation in real time, this is likely the better option.
It all depends on what you want to depict. I last did this sort of thing many years ago when MATLAB, and PCs in general, were slower, so getframe was the best option for me. I've used drawnow recently with good results, but with simpler code.

댓글을 달려면 로그인하십시오.

Ogen
Ogen 2016년 2월 10일

0 개 추천

How do you change the height of the cylinder and sphere?

댓글 수: 4

Star Strider
Star Strider 2016년 2월 10일
I believe this is what you want:
[Xc,Yc,Zc] = cylinder(0.5, 20);
Xcm = Xc;
Ycm = Yc;
Zcm = 2 * Zc; % <— Multiplied By ‘2’ To Double Cylinder Height
[Xs,Ys,Zs] = sphere(20);
Xsm = Xs * 2;
Ysm = Ys * 2;
Zsm = Zs + 3; % <— Added ‘1’ To Move Spheroid Up
figure(1)
surf(Xcm,Ycm,Zcm)
hold on
surf(Xsm,Ysm,Zsm)
hold off
grid on
axis equal
view([-35 20])
If it isn’t, let me know.
Note the changes I initially made to the original sphere matrices to distort it. You can do similar things with the cylinder radius. You can make it look like a bottle with the appropriate radius vector. It has to retain its essential cylinder properties, but it doesn’t have to just be a cylinder if you don’t want it to.
Ogen
Ogen 2016년 2월 10일
Yes that works. Thanks again
Star Strider
Star Strider 2016년 2월 11일
As always, my pleasure.
Star Strider
Star Strider 2016년 2월 11일

UPDATE — I did some Web searching, and discovered Dr. Jos Stam’s website at the University of Toronto http://www.dgp.toronto.edu/people/stam/reality/Research/pub.html. See specifically ‘Real-Time Fluid Dynamics for Games’. There’s also a CDROM, but I doubt the code’s written in MATLAB, so you’d have to adapt it. I found it through Mushroom Cloud Physics on ‘gamedev.net’. (I’m a gamer, so I can’t explain this not occurring to me earlier, other than that I do primarily medieval-themed games where mushroom clouds are rare and dragons are plentiful.)

If I find anything else, I’ll post it here.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Just for fun에 대해 자세히 알아보기

태그

질문:

2016년 2월 10일

댓글:

2016년 3월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by