I need help plotting a range of stream lines in my velocity field plot.

85 views (last 30 days)
I am new to matlab so please excuse my naivety. I need to plot streamlines for psi = [0:1:6] over the range -3<x<3. Any assistance would be greatly appreciated. Here is what I currently have;
[x,y] = meshgrid(-3:.5:3,-3:.5:3);
u = 2*y; % u velocity function
v = 1+(2*x); % v velocity function
xmarker = -0.5; %stagnation 'x' point
ymarker = 0; % stagnation 'y' point
figure
hold on
quiver (x,y,u,v)
plot(xmarker,ymarker,'r*') % stagnation point
axis([-3 3 -3 3])
%stream function
psi(0) = y^2 - x^2 - x -0.25

Accepted Answer

Ced
Ced on 25 Mar 2016
Hi
Nice plotting! I believe contour might help, something like
%stream function
psi = y.^2 - x.^2 - x -0.25;
contour(x,y,psi,[0:1:6])
Cheers

More Answers (2)

Harish babu
Harish babu on 12 Apr 2016
I need help plotting a range of stream lines for velocity and temperature plots in any numerical methods
  1 Comment
Jason Harvey
Jason Harvey on 12 Apr 2016
HI, I used a quiver plot to provide a velocity field across the plot window and added the contours, as suggested by Ced, and massaged the parameters/resolution to give the result I was looking for. This is the full code I came up with;
clear % clear all stored variables
close all % close all open figures
clc % clear command window
%list variables for velocity field%
[x,y] = meshgrid(-3:.5:3,-3:.5:3); % x and y values for velocity field
u = 2*y; % u velocity function
v = 1+(2*x); % v velocity function
xmarker = -0.5; %stagnation 'x' point
ymarker = 0; % stagnation 'y' point
%velocity plot%
figure % open a plot window
hold on; box on % hold current figure plot and place box around plot
quiver (x,y,u,v) % plot velocity vector field
plot(xmarker,ymarker,'r*') % stagnation point
axis([-3 3 -3 3]) % fix axis to desired range
title({'Aerodynamics Assignment 1';'Question 1 Velocity and Streamline plots'}) % plot title
%{
%stream function
x2 = [-3:.1:3]; y2 = [-3:.1:3];
psi = y2.^2 - x2.^2 - x2 -0.25; % stream function with constant determined from stagnation point
[C,h] = contour(x,y,psi,[1:1:6]); % plot stream lines from 1 to 6
[B,j] = contour(x,y,psi,[0:1:1],'-.'); % plot zero contour line dashed
clabel(C,h);clabel(B,j); % label contour values
%}
% streamline plots at finer resolution (0.14) to smooth out curves
x2 =[-3:.001:3];
% positive value curve set
psi0 = sqrt(x2.^2 +x2 + 0.25);
psi1 = sqrt(x2.^2 +x2 + 1.25);
psi2 = sqrt(x2.^2 +x2 + 2.25);
psi3 = sqrt(x2.^2 +x2 + 3.25);
psi4 = sqrt(x2.^2 +x2 + 4.25);
psi5 = sqrt(x2.^2 +x2 + 5.25);
psi6 = sqrt(x2.^2 +x2 + 6.25);
plot(x2,psi0,x2,psi1,x2,psi2,x2,psi3,x2,psi4,x2,psi5,x2,psi6)
% negative value curve set
psi00 = -sqrt(x2.^2 +x2 + 0.25);
psi11 = -sqrt(x2.^2 +x2 + 1.25);
psi22 = -sqrt(x2.^2 +x2 + 2.25);
psi33 = -sqrt(x2.^2 +x2 + 3.25);
psi44 = -sqrt(x2.^2 +x2 + 4.25);
psi55 = -sqrt(x2.^2 +x2 + 5.25);
psi66 = -sqrt(x2.^2 +x2 + 6.25);
plot(x2,psi00,x2,psi11,x2,psi22,x2,psi33,x2,psi44,x2,psi55,x2,psi66)
psi_half = sqrt(x2.^2 +x2 + 0.26);
psi0_half = -sqrt(x2.^2 +x2 + 0.26);
plot(x2,psi0_half,x2,psi_half);
Goodluck!

Sign in to comment.


Kavitha G N
Kavitha G N on 12 Sep 2023
Need help in plotting the stream lines. I have Orr-sommerfeld equation (1/aR)(D^2 - a^2)^2 Psi - 2i psi - (1-x^2)(D^2 - a^2) psi = c(D^2 - a^2)psi.I have to plot stream lines to this equation with boundaries psi(-1)=0 and psi(1)=0. I have written this but i coldnot validate. Can any one please help to correct this if there are any.
% Define the number of grid points and domain
N = 50; % Number of grid points
Lx = 10; % Streamwise domain length
Ly = 2; % Wall-normal domain length
% Define the x and y vectors based on the grid dimensions
x = linspace(0, Lx, N-1);
y = linspace(0, Ly, N-1);
[X,Y] = meshgrid(x,y);
% Define the Chebyshev differentiation matrix
[D, x] = cheb(N);
D2 = D^2;
D2 = D2(2:N, 2:N); % Remove boundary points
% Define the Orr-Sommerfeld operators A and B
I = eye(N-1);
a = 0.05; % Adjust the value of 'a' as needed
R = 500000; % Adjust the value of 'R' as needed
S = diag([0; 1./(1-x(2:N).^2); 0]);
D4 = (diag(1-x.^2)*D^4 - 8*diag(x)*D^3 - 12*D^2)*S;
D4 = D4(2:N, 2:N);
A = (D4 - 2*a^2*D2 + a^4*I) / (a*R) - 2i*I - 1i*diag(1-x(2:N).^2)*(D2 - a^2*I);
B = D2 - a^2*I;
% Calculate eigenvalues and eigenvectors
[vecs, vals] = eig(A, B);
% Find the eigenmode with the maximum growth rate
[max_growth, max_idx] = max(real(diag(vals)));
most_unstable_mode = vecs(:, max_idx);
real_most_unstable_mode =real(most_unstable_mode);
% Reshape the eigenmode to match the grid dimensions
psi = zeros(N-1, N-1);
psi(:, 1:N-1) =reshape(real_most_unstable_mode.*eye(N-1), [], N-1);
disp(psi);
% Create a 2D contour plot of the stream function
contour(X,Y,psi,100,'-b');
xlabel('x');
ylabel('y');
title('Stream Function');

Categories

Find more on Vector Fields in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!