Azzera filtri
Azzera filtri

Keeping getting gradient error and no figure 2

1 visualizzazione (ultimi 30 giorni)
Zachary
Zachary il 22 Apr 2024
Commentato: Zachary il 22 Apr 2024
function [] =ZacharyC1
clear all
clc
U=4.7;
m=6;
a=0.5;
[X,Y]=meshgrid (-2:0.05:-2,2:0.05:2);
r=sqrt(X.^2+Y.^2);
THETA=atan2(Y,X);
THETA1=atan2(Y,X+a);
THETA2=atan2(Y,X-a);
psi=U*r.*sin(THETA)+m*(THETA1-THETA2);
[DX,DY]=gradient(psi,.1,.1);
u=DY;
v=-DX;
contour (X,Y,psi,21);
hold on
quiver(X,Y,u,v,4)
hold off
[mm,nn]=size(u);
nnn=round(nn/3);
for i=1:mm
p(i,nnn)=0.5*U*U-0.5*(u(i,nnn)^2);
end
plot(p(:,nnn))
end

Risposte (1)

VBBV
VBBV il 22 Apr 2024
%function [] =ZacharyC1
clear all
clc
U=4.7;
m=6;
a=0.5;
[X,Y]=meshgrid (linspace(-2,2,100),linspace(-2,2,100));
r=sqrt(X.^2+Y.^2);
THETA=atan2(Y,X);
THETA1=atan2(Y,X+a);
THETA2=atan2(Y,X-a);
psi=U*r.*sin(THETA)+m*(THETA1-THETA2)
psi = 100x100
-7.8847 -7.8541 -7.8230 -7.7913 -7.7591 -7.7263 -7.6930 -7.6592 -7.6248 -7.5901 -7.5548 -7.5192 -7.4831 -7.4467 -7.4100 -7.3730 -7.3358 -7.2983 -7.2608 -7.2232 -7.1856 -7.1480 -7.1106 -7.0733 -7.0364 -6.9998 -6.9636 -6.9280 -6.8929 -6.8586 -7.6941 -7.6629 -7.6311 -7.5986 -7.5656 -7.5320 -7.4978 -7.4631 -7.4278 -7.3920 -7.3557 -7.3189 -7.2817 -7.2441 -7.2061 -7.1678 -7.1293 -7.0905 -7.0515 -7.0124 -6.9733 -6.9342 -6.8952 -6.8564 -6.8178 -6.7796 -6.7418 -6.7045 -6.6678 -6.6318 -7.5042 -7.4723 -7.4397 -7.4065 -7.3727 -7.3383 -7.3032 -7.2675 -7.2312 -7.1944 -7.1570 -7.1191 -7.0807 -7.0419 -7.0026 -6.9630 -6.9230 -6.8828 -6.8424 -6.8018 -6.7611 -6.7204 -6.6797 -6.6392 -6.5989 -6.5590 -6.5194 -6.4804 -6.4419 -6.4042 -7.3149 -7.2823 -7.2490 -7.2151 -7.1805 -7.1451 -7.1092 -7.0725 -7.0352 -6.9974 -6.9589 -6.9198 -6.8802 -6.8401 -6.7995 -6.7585 -6.7171 -6.6753 -6.6333 -6.5912 -6.5488 -6.5064 -6.4641 -6.4218 -6.3797 -6.3380 -6.2966 -6.2557 -6.2154 -6.1758 -7.1263 -7.0930 -7.0590 -7.0243 -6.9889 -6.9527 -6.9158 -6.8782 -6.8399 -6.8009 -6.7613 -6.7210 -6.6802 -6.6387 -6.5968 -6.5543 -6.5114 -6.4681 -6.4245 -6.3807 -6.3366 -6.2925 -6.2483 -6.2042 -6.1602 -6.1165 -6.0732 -6.0304 -5.9881 -5.9465 -6.9384 -6.9045 -6.8698 -6.8343 -6.7980 -6.7610 -6.7231 -6.6846 -6.6452 -6.6051 -6.5643 -6.5228 -6.4807 -6.4379 -6.3945 -6.3506 -6.3062 -6.2613 -6.2160 -6.1704 -6.1246 -6.0786 -6.0325 -5.9864 -5.9405 -5.8948 -5.8494 -5.8045 -5.7601 -5.7164 -6.7513 -6.7167 -6.6813 -6.6450 -6.6080 -6.5700 -6.5313 -6.4917 -6.4513 -6.4101 -6.3681 -6.3253 -6.2819 -6.2377 -6.1928 -6.1474 -6.1013 -6.0548 -6.0078 -5.9604 -5.9127 -5.8647 -5.8167 -5.7686 -5.7205 -5.6727 -5.6251 -5.5780 -5.5314 -5.4855 -6.5651 -6.5298 -6.4937 -6.4566 -6.4187 -6.3799 -6.3402 -6.2996 -6.2581 -6.2158 -6.1726 -6.1286 -6.0837 -6.0381 -5.9918 -5.9447 -5.8970 -5.8488 -5.7999 -5.7507 -5.7010 -5.6510 -5.6009 -5.5506 -5.5004 -5.4503 -5.4004 -5.3509 -5.3020 -5.2537 -6.3797 -6.3438 -6.3069 -6.2691 -6.2304 -6.1907 -6.1500 -6.1084 -6.0659 -6.0224 -5.9779 -5.9326 -5.8864 -5.8393 -5.7914 -5.7428 -5.6933 -5.6433 -5.5926 -5.5413 -5.4896 -5.4375 -5.3852 -5.3327 -5.2801 -5.2276 -5.1753 -5.1234 -5.0719 -5.0211 -6.1952 -6.1586 -6.1211 -6.0825 -6.0430 -6.0024 -5.9608 -5.9182 -5.8745 -5.8299 -5.7842 -5.7375 -5.6899 -5.6413 -5.5919 -5.5415 -5.4903 -5.4384 -5.3857 -5.3324 -5.2786 -5.2243 -5.1697 -5.1148 -5.0598 -5.0048 -4.9499 -4.8953 -4.8412 -4.7877
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
[DX,DY]=gradient(psi,.1);
u=DY;
v=-DX;
contour (X,Y,psi,21);
hold on
quiver(X,Y,u,v,4)
hold off
[mm,nn]=size(u);
nnn=round(nn/3);
for i=1:mm
p(i,nnn)=0.5*U*U-0.5*(u(i,nnn)^2);
end
plot(p(:,nnn))
%end
  2 Commenti
VBBV
VBBV il 22 Apr 2024
Use linspace for generation of datagrid points.
Zachary
Zachary il 22 Apr 2024
Thank you. I got figure 1, but how do I find figure 2. It didn't pop up.

Accedi per commentare.

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by