Horizontal Freestream Flow Issues With Symbolic Math Toolbox

1 Ansicht (letzte 30 Tage)
I am attempting to plot stictly horizontal freestream flow using fcontour and the Symbolic Math toolbox. A few days ago I was able to successfully achieve this with the code below. However, starting last night whenever I run the script the "symbolic method" produces vertical contour lines that indicate stricty vertical freestram flow. I have gone back to the original code to ensure nothing I changed in the script had an impact, but the issue still remains. I have included an image of the incorrect plot (from the symbolic method) vs. the correct plot (from the numerical method) to better illustrate the problem. I would love some guidance on what to try and fix this strange issue.
clear
clc
% use the symbolic method to create the stream function for freestream flow
% and plot it
syms xs ys
Uval = 1;
Vval = 0;
psi_fs = Uval*ys - Vval*xs;
figure(4)
fcontour(psi_fs,[-3 3 -5 5],'k'); %'k' makes all the lines black
% use the numerical method to create the stream function for freestream
% flow and plot it
xlocs = [-3:.1:3]; % you can use linspace for this
ylocs = [-3:.1:3];
% make the grid of points x horizontal, y vertical
[xmat,ymat] = meshgrid(xlocs,ylocs);
psi_vals_fs = Uval*ymat - Vval*xmat;
figure(5)
contour(xmat, ymat, psi_vals_fs,'k') % 'k' makes all the lines black

Akzeptierte Antwort

Star Strider
Star Strider am 31 Jan. 2025
The ‘ZData’ matrix from the symbolic code appear to be transposed with respect to ‘psi_vals_fs’. This is likely due to the assumptions that fcontour makes with the data. See Algorithms to understand what it is doing. (It may be interpreting ‘y’ as ‘x’ since the arguments are not specifically stated.) Providing the function with appropriate argumentts seems to solve it.
clear
clc
% use the symbolic method to create the stream function for freestream flow
% and plot it
syms xs ys
Uval = 1;
Vval = 0;
psi_fs(xs,ys) = Uval*ys - Vval*xs;
figure(4)
hf = fcontour(psi_fs,[-3 3 -3 3],'k'); %'k' makes all the lines black <— LIMITS CHANGED TO MATCH THE NUMERIC CODE
get(hf)
Annotation: [1x1 matlab.graphics.eventdata.Annotation] BeingDeleted: off BusyAction: 'queue' ButtonDownFcn: '' Children: [0x0 GraphicsPlaceholder] ContextMenu: [0x0 GraphicsPlaceholder] ContourMatrix: [2x432 double] CreateFcn: '' DataTipTemplate: [1x1 matlab.graphics.datatip.DataTipTemplate] DeleteFcn: '' DisplayName: '{ys}' Fill: off Function: [1x1 symfun] HandleVisibility: 'on' HitTest: on Interruptible: on LevelList: [-3 -2 -1 0 1 2 3] LevelListMode: 'auto' LevelStep: 1 LevelStepMode: 'auto' LineColor: [0 0 0] LineStyle: '-' LineWidth: 0.5000 MeshDensity: 71 Parent: [1x1 Axes] PickableParts: 'visible' Selected: off SelectionHighlight: on Tag: '' Type: 'functioncontour' UserData: [] Visible: on XData: [71x71 double] XRange: [-3 3] XRangeMode: 'manual' YData: [71x71 double] YRange: [-3 3] YRangeMode: 'manual' ZData: [71x71 double]
Zm = hf.ZData
Zm = 71×71
-3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.9143 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.8286 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.7429 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.6571 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.5714 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4857 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.3143 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286 -2.2286
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% use the numerical method to create the stream function for freestream
% flow and plot it
xlocs = [-3:.1:3]; % you can use linspace for this
ylocs = [-3:.1:3];
% make the grid of points x horizontal, y vertical
[xmat,ymat] = meshgrid(xlocs,ylocs);
psi_vals_fs = Uval*ymat - Vval*xmat
psi_vals_fs = 61×61
-3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.9000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.8000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.7000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.5000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.4000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.3000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.2000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000 -2.1000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure(5)
contour(xmat, ymat, psi_vals_fs,'k') % 'k' makes all the lines black
.
  2 Kommentare
Trevor John
Trevor John am 31 Jan. 2025
Thank you very much for your help, this seems to fix my issue! This is my first time working with the Symbolic Math Toolbox so I am unfamilliar with the functions and didn't realize that I could add arguments to the 'psi_fs' function or ones similar to it. I really appreciate it!
Star Strider
Star Strider am 31 Jan. 2025
As always, my pleasure!
There are many features of MATLAB and the Toolboxes that I’m still discovering, too. New functions and capabilities continue to be added, expanded, or changed.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by