trying to plot 3 variables in 3d

1 vue (au cours des 30 derniers jours)
joshua payne
joshua payne le 2 Nov 2022
Réponse apportée : Voss le 2 Nov 2022
clc
clear all
theta= linspace(.01, .55) %for thetamax = 32 degrees
M=linspace(2,5)
gamma=1.4
lambda3=sqrt((((M.^2)-1).^2)-3.*(1+((gamma-1)/2).*(M.^2)).*(1+((gamma+1)/2).*(M.^2)).*(tan(theta)).^2);
chi=(1./(lambda3.^3)).*((((M.^2)-1).^3)-9.*(1+((gamma-1)./2).*(M.^2)).*(1+((gamma-1)/2).*(M.^2)+((gamma+1)./4).*(M.^4)).*((tan(theta)).^2));
beta= atan(((M.^2)-1+2.*lambda3.*cos((4.*pi+acos(chi))./3))./(3.*(1+((gamma-1)/2).*(M.^2)).*tan(theta)))
M1n=M.*sin(beta)
strength=1+((2*gamma)/(gamma+1)).*((M1n.^2) -1)
figure
surf(M, beta,strength)
im trying to 3d plot strength vs M and beta but it keeps saying strength isnt a matrix.

Réponse acceptée

Davide Masiello
Davide Masiello le 2 Nov 2022
Modifié(e) : Davide Masiello le 2 Nov 2022
surf can handle only matrices, so this is what you want to do
theta= linspace(.01, .55); %for thetamax = 32 degrees
M=linspace(2,5);
gamma=1.4;
lambda3=sqrt((((M.^2)-1).^2)-3.*(1+((gamma-1)/2).*(M.^2)).*(1+((gamma+1)/2).*(M.^2)).*(tan(theta)).^2);
chi=(1./(lambda3.^3)).*((((M.^2)-1).^3)-9.*(1+((gamma-1)./2).*(M.^2)).*(1+((gamma-1)/2).*(M.^2)+((gamma+1)./4).*(M.^4)).*((tan(theta)).^2));
beta= atan(((M.^2)-1+2.*lambda3.*cos((4.*pi+acos(chi))./3))./(3.*(1+((gamma-1)/2).*(M.^2)).*tan(theta)));
[M,beta] = meshgrid(M,beta);
M1n=M.*sin(beta);
strength=1+((2*gamma)/(gamma+1)).*((M1n.^2) -1)
strength = 100×100
1.0327 1.0694 1.1065 1.1443 1.1825 1.2214 1.2607 1.3007 1.3411 1.3822 1.4237 1.4659 1.5085 1.5518 1.5956 1.6399 1.6848 1.7302 1.7762 1.8227 1.8698 1.9174 1.9656 2.0144 2.0636 2.1135 2.1639 2.2148 2.2663 2.3183 1.0154 1.0515 1.0881 1.1253 1.1630 1.2013 1.2401 1.2794 1.3193 1.3598 1.4007 1.4423 1.4843 1.5269 1.5701 1.6138 1.6580 1.7028 1.7481 1.7939 1.8403 1.8873 1.9348 1.9828 2.0314 2.0805 2.1302 2.1804 2.2311 2.2824 0.9992 1.0348 1.0709 1.1075 1.1447 1.1825 1.2208 1.2596 1.2989 1.3388 1.3792 1.4201 1.4616 1.5036 1.5462 1.5893 1.6329 1.6771 1.7218 1.7670 1.8128 1.8591 1.9059 1.9533 2.0012 2.0496 2.0986 2.1481 2.1982 2.2487 0.9840 1.0191 1.0548 1.0910 1.1277 1.1649 1.2027 1.2410 1.2798 1.3192 1.3591 1.3995 1.4404 1.4819 1.5239 1.5664 1.6095 1.6531 1.6972 1.7418 1.7870 1.8327 1.8789 1.9257 1.9730 2.0208 2.0691 2.1180 2.1674 2.2173 0.9698 1.0045 1.0397 1.0755 1.1117 1.1485 1.1858 1.2237 1.2620 1.3009 1.3403 1.3802 1.4207 1.4616 1.5031 1.5451 1.5876 1.6307 1.6742 1.7183 1.7630 1.8081 1.8537 1.8999 1.9466 1.9938 2.0416 2.0899 2.1386 2.1880 0.9566 0.9909 1.0257 1.0611 1.0969 1.1333 1.1701 1.2075 1.2454 1.2839 1.3228 1.3623 1.4022 1.4427 1.4837 1.5252 1.5673 1.6098 1.6529 1.6965 1.7406 1.7852 1.8303 1.8759 1.9221 1.9688 2.0160 2.0637 2.1119 2.1606 0.9444 0.9783 1.0127 1.0477 1.0831 1.1191 1.1556 1.1925 1.2300 1.2680 1.3065 1.3456 1.3851 1.4252 1.4657 1.5068 1.5483 1.5904 1.6330 1.6761 1.7197 1.7639 1.8085 1.8536 1.8993 1.9455 1.9921 2.0393 2.0870 2.1352 0.9330 0.9666 1.0007 1.0352 1.0703 1.1059 1.1420 1.1786 1.2157 1.2534 1.2915 1.3301 1.3692 1.4089 1.4490 1.4897 1.5308 1.5725 1.6146 1.6573 1.7004 1.7441 1.7883 1.8330 1.8782 1.9239 1.9701 2.0168 2.0640 2.1117 0.9225 0.9558 0.9895 1.0238 1.0585 1.0938 1.1295 1.1658 1.2025 1.2398 1.2776 1.3158 1.3546 1.3938 1.4336 1.4738 1.5146 1.5558 1.5976 1.6399 1.6826 1.7259 1.7696 1.8139 1.8586 1.9039 1.9497 1.9959 2.0427 2.0899 0.9128 0.9458 0.9792 1.0132 1.0476 1.0826 1.1180 1.1540 1.1904 1.2273 1.2647 1.3026 1.3411 1.3800 1.4194 1.4593 1.4997 1.5405 1.5819 1.6238 1.6662 1.7091 1.7524 1.7963 1.8407 1.8855 1.9309 1.9767 2.0230 2.0699
figure
surf(M, beta,strength)

Plus de réponses (1)

Voss
Voss le 2 Nov 2022
clc
clear all
theta= linspace(.01, .55); %for thetamax = 32 degrees
M=linspace(2,5);
gamma=1.4;
lambda3=sqrt((((M.^2)-1).^2)-3.*(1+((gamma-1)/2).*(M.^2)).*(1+((gamma+1)/2).*(M.^2)).*(tan(theta)).^2);
chi=(1./(lambda3.^3)).*((((M.^2)-1).^3)-9.*(1+((gamma-1)./2).*(M.^2)).*(1+((gamma-1)/2).*(M.^2)+((gamma+1)./4).*(M.^4)).*((tan(theta)).^2));
beta= atan(((M.^2)-1+2.*lambda3.*cos((4.*pi+acos(chi))./3))./(3.*(1+((gamma-1)/2).*(M.^2)).*tan(theta)));
% transpose beta to get the appropriate matrix M1n:
M1n=M.*sin(beta.')
M1n = 100×100
1.0139 1.0293 1.0447 1.0600 1.0754 1.0907 1.1061 1.1215 1.1368 1.1522 1.1676 1.1829 1.1983 1.2137 1.2290 1.2444 1.2597 1.2751 1.2905 1.3058 1.3212 1.3366 1.3519 1.3673 1.3826 1.3980 1.4134 1.4287 1.4441 1.4595 1.0066 1.0218 1.0371 1.0523 1.0676 1.0828 1.0981 1.1133 1.1286 1.1438 1.1591 1.1743 1.1896 1.2048 1.2201 1.2353 1.2506 1.2658 1.2811 1.2963 1.3116 1.3269 1.3421 1.3574 1.3726 1.3879 1.4031 1.4184 1.4336 1.4489 0.9996 1.0148 1.0299 1.0451 1.0602 1.0754 1.0905 1.1057 1.1208 1.1360 1.1511 1.1662 1.1814 1.1965 1.2117 1.2268 1.2420 1.2571 1.2723 1.2874 1.3026 1.3177 1.3329 1.3480 1.3631 1.3783 1.3934 1.4086 1.4237 1.4389 0.9931 1.0082 1.0232 1.0383 1.0533 1.0683 1.0834 1.0984 1.1135 1.1285 1.1436 1.1586 1.1737 1.1887 1.2038 1.2188 1.2339 1.2489 1.2640 1.2790 1.2941 1.3091 1.3241 1.3392 1.3542 1.3693 1.3843 1.3994 1.4144 1.4295 0.9870 1.0019 1.0169 1.0318 1.0468 1.0617 1.0767 1.0917 1.1066 1.1216 1.1365 1.1515 1.1664 1.1814 1.1963 1.2113 1.2262 1.2412 1.2562 1.2711 1.2861 1.3010 1.3160 1.3309 1.3459 1.3608 1.3758 1.3907 1.4057 1.4207 0.9812 0.9961 1.0110 1.0258 1.0407 1.0556 1.0704 1.0853 1.1002 1.1150 1.1299 1.1448 1.1596 1.1745 1.1894 1.2042 1.2191 1.2340 1.2488 1.2637 1.2786 1.2934 1.3083 1.3232 1.3380 1.3529 1.3678 1.3826 1.3975 1.4124 0.9759 0.9907 1.0054 1.0202 1.0350 1.0498 1.0646 1.0794 1.0942 1.1089 1.1237 1.1385 1.1533 1.1681 1.1829 1.1977 1.2124 1.2272 1.2420 1.2568 1.2716 1.2864 1.3012 1.3159 1.3307 1.3455 1.3603 1.3751 1.3899 1.4047 0.9709 0.9856 1.0003 1.0150 1.0297 1.0444 1.0591 1.0738 1.0885 1.1033 1.1180 1.1327 1.1474 1.1621 1.1768 1.1915 1.2062 1.2209 1.2356 1.2504 1.2651 1.2798 1.2945 1.3092 1.3239 1.3386 1.3533 1.3680 1.3827 1.3975 0.9662 0.9809 0.9955 1.0101 1.0248 1.0394 1.0541 1.0687 1.0833 1.0980 1.1126 1.1273 1.1419 1.1565 1.1712 1.1858 1.2004 1.2151 1.2297 1.2444 1.2590 1.2736 1.2883 1.3029 1.3176 1.3322 1.3468 1.3615 1.3761 1.3908 0.9619 0.9765 0.9911 1.0056 1.0202 1.0348 1.0494 1.0639 1.0785 1.0931 1.1077 1.1222 1.1368 1.1514 1.1660 1.1805 1.1951 1.2097 1.2243 1.2388 1.2534 1.2680 1.2826 1.2971 1.3117 1.3263 1.3409 1.3554 1.3700 1.3846
strength=1+((2*gamma)/(gamma+1)).*((M1n.^2) -1);
figure
surf(M, beta,strength)
xlabel('M')
ylabel('beta')
zlabel('strength')

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by