Plotting a result with 3 different variables

2 visualizzazioni (ultimi 30 giorni)
Hi everybody,
I have a equation that has three variables (Ca, Ka and W). I am trying to get the result for each Ca, Ka and W values and plot the results. If I assign 10 variables from 1 to 10 to each of them then I'd like to have 10*10*10=1000 results for my equation. I used linspace command but it gave me total of 10 results where each of my variables started from 1 and increased to 10 all together. Is there a way to create a code to assign those variables individually?
I am truly a newbie in Matlab so I apologize if I'm asking a really dumb question :)
clear all
close all
clc
Ca = linspace(1,10,10);
Ka = linspace(1,10,10);
W = linspace(1,10,10);
fun(Ca,Ka,W)
function Tr = fun(Ca,Ka,W,ma,m,k,Mu,W0,Zeta,Wa,Beta,ra,b,c,d,e,f,g)
ma=2;
m=40;
k=25;
Mu=ma/m;
W0=sqrt(k/m);
Zeta=Ca/(2*ma*W0);
Wa=sqrt(Ka/ma);
Beta= sqrt(Wa/W0);
r=W/W0;
Tr = sqrt(((2.*Zeta.*r).^2+(r.^2-Beta.^2).^2)./((2.*Zeta.*r).^2.*(r.^2-1+Mu.*r.^2).^2+(Mu.*r.^2.*Beta.^2-(r.^2-1).*(r.^2-Beta.^2)).^2));
plot (W,Tr)
end
  1 Commento
Rik
Rik il 20 Dic 2022
You probably want ndgrid, although I don't fully understand what you want. Can you explain what results you want to see?

Accedi per commentare.

Risposta accettata

Torsten
Torsten il 20 Dic 2022
Modificato: Torsten il 20 Dic 2022
To plot, you will have to keep one parameter constant and plot "result" over the two remaining parameters.
Ca = linspace(1,10,10);
Ka = linspace(1,10,10);
W = linspace(1,10,10);
[ca,ka,w]=ndgrid(Ca,Ka,W);
result = fun(ca,ka,w)
result =
result(:,:,1) = 1.6465 1.5682 1.4523 1.3668 1.3246 1.3097 1.3081 1.3121 1.3183 1.3251 1.5293 1.4962 1.4659 1.4413 1.4227 1.4094 1.4003 1.3942 1.3904 1.3881 1.4984 1.4821 1.4685 1.4573 1.4480 1.4405 1.4344 1.4296 1.4257 1.4227 1.4866 1.4771 1.4694 1.4630 1.4576 1.4530 1.4491 1.4457 1.4428 1.4404 1.4810 1.4747 1.4698 1.4657 1.4622 1.4591 1.4564 1.4541 1.4520 1.4501 1.4778 1.4735 1.4701 1.4672 1.4647 1.4625 1.4606 1.4589 1.4573 1.4559 1.4759 1.4727 1.4702 1.4681 1.4663 1.4646 1.4632 1.4619 1.4607 1.4596 1.4747 1.4722 1.4703 1.4687 1.4673 1.4660 1.4649 1.4639 1.4629 1.4620 1.4738 1.4719 1.4704 1.4691 1.4680 1.4670 1.4661 1.4652 1.4645 1.4638 1.4732 1.4716 1.4704 1.4694 1.4685 1.4677 1.4669 1.4662 1.4656 1.4650 result(:,:,2) = 0.1859 0.1866 0.1872 0.1878 0.1883 0.1888 0.1892 0.1897 0.1902 0.1906 0.1837 0.1840 0.1842 0.1844 0.1845 0.1846 0.1847 0.1848 0.1848 0.1849 0.1814 0.1815 0.1815 0.1814 0.1814 0.1814 0.1813 0.1812 0.1812 0.1811 0.1797 0.1796 0.1795 0.1795 0.1794 0.1793 0.1792 0.1791 0.1790 0.1789 0.1785 0.1784 0.1783 0.1782 0.1781 0.1780 0.1779 0.1778 0.1777 0.1777 0.1776 0.1775 0.1774 0.1773 0.1772 0.1772 0.1771 0.1770 0.1770 0.1769 0.1770 0.1769 0.1768 0.1767 0.1767 0.1766 0.1766 0.1765 0.1764 0.1764 0.1766 0.1765 0.1764 0.1763 0.1763 0.1762 0.1762 0.1761 0.1761 0.1760 0.1762 0.1762 0.1761 0.1761 0.1760 0.1760 0.1759 0.1759 0.1758 0.1758 0.1760 0.1759 0.1759 0.1758 0.1758 0.1758 0.1757 0.1757 0.1757 0.1756 result(:,:,3) = 0.0748 0.0749 0.0750 0.0750 0.0751 0.0752 0.0752 0.0753 0.0753 0.0754 0.0744 0.0745 0.0745 0.0746 0.0747 0.0747 0.0747 0.0748 0.0748 0.0749 0.0739 0.0740 0.0740 0.0740 0.0741 0.0741 0.0741 0.0741 0.0742 0.0742 0.0734 0.0735 0.0735 0.0735 0.0735 0.0735 0.0735 0.0735 0.0735 0.0735 0.0730 0.0730 0.0730 0.0730 0.0730 0.0730 0.0730 0.0730 0.0730 0.0730 0.0726 0.0726 0.0726 0.0726 0.0726 0.0726 0.0726 0.0726 0.0726 0.0726 0.0723 0.0723 0.0723 0.0723 0.0723 0.0723 0.0723 0.0723 0.0723 0.0723 0.0721 0.0721 0.0721 0.0721 0.0721 0.0720 0.0720 0.0720 0.0720 0.0720 0.0719 0.0719 0.0719 0.0719 0.0719 0.0718 0.0718 0.0718 0.0718 0.0718 0.0717 0.0717 0.0717 0.0717 0.0717 0.0717 0.0717 0.0717 0.0717 0.0717 result(:,:,4) = 0.0407 0.0407 0.0407 0.0408 0.0408 0.0408 0.0408 0.0408 0.0409 0.0409 0.0406 0.0406 0.0406 0.0407 0.0407 0.0407 0.0407 0.0407 0.0407 0.0407 0.0404 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0403 0.0403 0.0403 0.0403 0.0403 0.0403 0.0403 0.0403 0.0403 0.0403 0.0401 0.0401 0.0401 0.0401 0.0401 0.0401 0.0401 0.0401 0.0401 0.0401 0.0399 0.0399 0.0399 0.0399 0.0399 0.0399 0.0399 0.0399 0.0399 0.0399 0.0397 0.0397 0.0397 0.0397 0.0397 0.0397 0.0397 0.0397 0.0397 0.0397 0.0396 0.0396 0.0396 0.0396 0.0396 0.0396 0.0396 0.0396 0.0396 0.0396 0.0395 0.0395 0.0395 0.0395 0.0395 0.0395 0.0395 0.0395 0.0395 0.0395 0.0394 0.0394 0.0394 0.0394 0.0394 0.0394 0.0394 0.0394 0.0394 0.0394 result(:,:,5) = 0.0257 0.0257 0.0257 0.0257 0.0257 0.0257 0.0257 0.0257 0.0257 0.0257 0.0256 0.0256 0.0256 0.0256 0.0256 0.0257 0.0257 0.0257 0.0257 0.0257 0.0256 0.0256 0.0256 0.0256 0.0256 0.0256 0.0256 0.0256 0.0256 0.0256 0.0255 0.0255 0.0255 0.0255 0.0255 0.0255 0.0255 0.0255 0.0255 0.0255 0.0254 0.0254 0.0254 0.0254 0.0254 0.0254 0.0254 0.0254 0.0254 0.0254 0.0253 0.0253 0.0253 0.0253 0.0253 0.0253 0.0253 0.0253 0.0253 0.0253 0.0252 0.0252 0.0252 0.0252 0.0252 0.0252 0.0252 0.0252 0.0252 0.0252 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0251 0.0250 0.0250 0.0250 0.0250 0.0250 0.0250 0.0250 0.0250 0.0250 0.0250 result(:,:,6) = 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0177 0.0176 0.0176 0.0176 0.0176 0.0176 0.0176 0.0176 0.0176 0.0176 0.0177 0.0176 0.0176 0.0176 0.0176 0.0176 0.0176 0.0176 0.0176 0.0176 0.0176 0.0175 0.0175 0.0175 0.0175 0.0176 0.0176 0.0176 0.0176 0.0176 0.0176 0.0175 0.0175 0.0175 0.0175 0.0175 0.0175 0.0175 0.0175 0.0175 0.0175 0.0174 0.0174 0.0174 0.0174 0.0174 0.0175 0.0175 0.0175 0.0175 0.0175 0.0174 0.0174 0.0174 0.0174 0.0174 0.0174 0.0174 0.0174 0.0174 0.0174 0.0173 0.0173 0.0173 0.0173 0.0173 0.0174 0.0174 0.0174 0.0174 0.0174 0.0173 0.0173 0.0173 0.0173 0.0173 0.0173 0.0173 0.0173 0.0173 0.0173 result(:,:,7) = 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0128 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0129 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0128 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 0.0127 result(:,:,8) = 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0098 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0099 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0098 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 0.0097 result(:,:,9) = 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0077 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0078 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 0.0077 result(:,:,10) = 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0063 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062 0.0062
function Tr = fun(Ca,Ka,W,ma,m,k,Mu,W0,Zeta,Wa,Beta,ra,b,c,d,e,f,g)
ma=2;
m=40;
k=25;
Mu=ma/m;
W0=sqrt(k/m);
Zeta=Ca/(2*ma*W0);
Wa=sqrt(Ka/ma);
Beta= sqrt(Wa/W0);
r=W/W0;
Tr = sqrt(((2.*Zeta.*r).^2+(r.^2-Beta.^2).^2)./((2.*Zeta.*r).^2.*(r.^2-1+Mu.*r.^2).^2+(Mu.*r.^2.*Beta.^2-(r.^2-1).*(r.^2-Beta.^2)).^2));
%plot (W,Tr)
end
  2 Commenti
Tuncer
Tuncer il 22 Dic 2022
That seems to be solving my problem. Thanks a lot!
Rik
Rik il 22 Dic 2022
If this answer solved your question, please consider marking it as accepted answer. If not, feel free to comment with your remaining issues.

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by