MATLAB Answers

Plotting a rankine half body

조회 수: 96(최근 30일)
Randy Chen
Randy Chen 20 Oct 2020
댓글: Randy Chen 20 Oct 2020
I'm trying to plot a rankine half body, a flow field formed by superposition of a horizontal uniform flow and a source flow. The figure turned out to be a mess, I don't know how I should fix it. Here are my codes:
clc;
clear all;
m=3; %strength
U = 30;%positive x-axis
%Mesh for fourth quadrant and corresponding stream value function
[X1,Y1] = meshgrid(.05:.1:30,-30:.1:-.05);
psi1 = U*Y1 + (m/(2*pi))*atan(Y1./X1);
%Mesh for first quadrant and corresponding stream value function
[X2,Y2] = meshgrid(.05:.1:30,.05:.1:30);
psi2 = U*Y2 + (m/(2*pi))*atan(Y2./X2);
%Mesh for second quadrant and corresponding stream value function
[X3,Y3] = meshgrid(-30:.1:-.05,.05:.1:30);
psi3 = U*Y3 + (m/(2*pi))*atan(Y3./X3);
%Mesh for third quadrant and corresponding stream value function
[X4,Y4] = meshgrid(-30:.1:-.05,-30:.1:-.05);
psi4 = U*Y4 + (m/(2*pi))*atan(Y4./X4);
figure (1)
A='on';
B = 2;
C = 2.5;
contour(X1,Y1,psi1,'k','showtext',A,'textstep',B,'levelstep',C);
hold on;
contour(X2,Y2,psi2,'k','showtext',A,'textstep',B,'levelstep',C);
hold on;
contour(X3,Y3,psi3,'k','showtext',A,'textstep',B,'levelstep',C);
hold on;
contour(X4,Y4,psi4,'k','showtext',A,'textstep',B,'levelstep',C);
hold off;
xlim([-30 30]);ylim([-30 30]);
xlabel('X');ylabel('Y');
grid on;
'''
Here is the figure I got:
However, it should at least look something like this:

  댓글 수: 0

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

채택된 답변

Alan Stevens
Alan Stevens 20 Oct 2020
편집: Alan Stevens 20 Oct 2020
Try this
m=3; %strength
U = 20;%positive x-axis
%Mesh for fourth quadrant and corresponding stream value function
[X1,Y1] = meshgrid(0.005:0.01:3,-3:0.01:-0.005);
psi1 = U*Y1 + (m/(2*pi))*atan(Y1./X1);
% %Mesh for first quadrant and corresponding stream value function
[X2,Y2] = meshgrid(0.005:.01:3,0.005:.01:3);
psi2 = U*Y2 + (m/(2*pi))*atan(Y2./X2);
% %Mesh for second quadrant and corresponding stream value function
[X3,Y3] = meshgrid(-3:.01:-0.005,0.005:.01:3);
psi3 = U*Y3 + (m/(2*pi))*atan(Y3./X3);
% %Mesh for third quadrant and corresponding stream value function
[X4,Y4] = meshgrid(-3:.01:-0.005,-3:.01:-0.005);
psi4 = U*Y4 + (m/(2*pi))*atan(Y4./X4);
figure (1)
A='on';
B = 2;
C = 5;
contour(X1,Y1,psi1,'k','ShowText',A,'TextStep',B,'LevelStep',C);
hold on;
contour(X2,Y2,psi2,'k','ShowText',A,'TextStep',B,'LevelStep',C);
contour(X3,Y3,psi3,'k','ShowText',A,'TextStep',B,'LevelStep',C);
contour(X4,Y4,psi4,'k','ShowText',A,'TextStep',B,'LevelStep',C);
xlim([-4 4]);ylim([-4 4]);
xlabel('X');ylabel('Y');
grid on;
In your original you were plotting so many contours they were all on top of each other!

  댓글 수: 2

Alan Stevens
Alan Stevens 20 Oct 2020
Here's a leaner version:
lo = -30; hi = 30;
x = linspace(lo, hi, 200);
m = 1000; %strength
U = 30;%positive x-axis
[X1,Y1] = meshgrid(x,-x);
psi1 = U*Y1 + (m/(2*pi))*atan(Y1./X1);
figure (1)
A='on';
B = 200;
C = 50;
contour(X1,Y1,psi1,'k','ShowText',A,'TextStep',B,'LevelStep',C);
xlim([-hi hi]);ylim([-hi hi]);
xlabel('X');ylabel('Y');
grid on;
It produces this:
Randy Chen
Randy Chen 20 Oct 2020
omg thank yall so much!

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by