How can I combine these two codes
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I need help creating a plot of streamlines over an ellipse for a school assignment
The two codes that I am using are
% Plot streamlines and pressure coefficent of an unviscious,uncomprimibile,irrotational
% flow around a cylinder section (radius = 1) that spins around the z axis (coming out
% of the xy plane).
% This result is achieved by superimposition of elementary solution of the potential
% function PHI, where [Ux , Uy] = GRAD(PHI) which comprehend Uniform Stream,Doublet,Vortex.
% This case rappresents a good example of Magnus Effect,that is the reason why spinning
% balls have an effected trajectory.And rappresent the basis of Kutta-Joukowski theory.
%
%
% INPUT
% V_i = Asymptotic Speed
% G = Angular Speed (positive anti-clockwise)
%
% -----EXAMPLE------
% V_i = 20
% G = 50
%
% Created by: Dario Isola
% DATA : 24/03/2004
% Politecnico di Milano - Aerospatial Engeeniering Departement
%----------
%Modification log
%Author Date Description
%----------------------------------------------------------------------------------
%Yogesh PARTE,IMT Toulouse 15 Jan 2010 Added Cp distribution plot
% over a cylinder see
% figure(4), removed for loop, added comments
%----------------------------------------------------------------------------------
close all;
clear all;
%%Input section
V_i = input(' Asymptotic speed V_0 [m/s] = ');
G = input(' Circulation Value G [rad/s] [Anti-clockwise] = ');
%%Actual computation
%Radius of the circle
a = 3.5 ;
c =-a*2;
b =a*2;
% Number of intervals
n =a*50;
[x,y]=meshgrid([c:(b-c)/n:b],[c:(b-c)/n:b]');
warning off;
%%Preliminary DATA & purification
% Set values of X and Y inside the cylinder to zero
[I J]=find( (x.^2+y.^2) < a);
if ~isempty(I)
x(I,J) = 0;
y(I,J) = 0;
end
%Definition of polar variables
rho=sqrt(x.^2+y.^2);
theta=atan2(y,x);
% Creation of the streamline function
z=V_i.*sin(theta).*rho.*(1-(a^2./(rho.^2)))-G*log(rho)/(2*pi);
%%Generate unite cicle for plotting
n=100;
r=ones(1,n+1)*a;
t=[0:2*pi/n:2*pi];
Xcircle = r.*cos(t);
Ycircle = r.*sin(t);
%%Plot the data
% Streamline Plot
figure(1);
contour(x,y,z,25);
colorbar;
hold on;
fill(Xcircle,Ycircle,'k');
title('Stream Lines');
xlabel('x \rightarrow');
ylabel('y \rightarrow');
axis square;
This is code that I found online for streamlines over a circle.
The other code is
clc,clear
a=5.5; %horizontal radius
b=3.50; %vertical radius
x0=0; % x0,y0 ellipse centre coordinates
y0=0;
t=-pi:0.01:pi;
x=x0+a*cos(t);
w=y0+b*sin(t);
plot(x,w)
grid on
This is to plot an ellipse.
My problem is that I need the second code to be somehow integrated into the first code which is the stream line code.
Any help would be great because my professor would like to see some sort of MATLAB use out of our project.
Thank you.
0 Commenti
Risposte (1)
Geoff Hayes
il 19 Apr 2015
Haim - just convert the second script into a function so that you can call it from the first function (make sure that you acknowledge the author of this code, Azzi Abdelmalek at http://www.mathworks.com/matlabcentral/answers/86615-how-to-plot-an-ellipse). Do something like
function [x,w] = getEllipse(a,b,x0,y0)
% a - horizontal radius
% b - vertical radius
% x0,y0 ellipse centre coordinates
t=-pi:0.01:pi;
x=x0+a*cos(t);
w=y0+b*sin(t);
2 Commenti
Geoff Hayes
il 19 Apr 2015
Haim - how have you changed the code? Please describe what you have tried to do and what errors you are encountering.
Vedere anche
Categorie
Scopri di più su Vector Fields in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!