plot to the function
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Junway
am 9 Apr. 2021
Beantwortet: DGM
am 9 Apr. 2021
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/577942/image.png)
This is function
when r 0 to 3
when z 0, 0.03, 0.2, 0.5, 1,2
can you help me plot?
do i use vector or for loop or calculate each part and put in matlab?
0 Kommentare
Akzeptierte Antwort
KALYAN ACHARJYA
am 9 Apr. 2021
Bearbeitet: KALYAN ACHARJYA
am 9 Apr. 2021
Hint:
z=[0, 0.03, 0.2, 0.5, 1,2];
r=0:0.01:3;
for i=1:length(z)
eq=..... % Here z(i)
plot(eq); % r vs. eq
hold on;
end
Add legend for z values
0 Kommentare
Weitere Antworten (1)
DGM
am 9 Apr. 2021
If you're using a relatively new version, this should work. Avoid loops where possible. In this case, you don't need any.
r = linspace(0,3,20); % use a fine vector for this one
z = [0 0.03 0.2 0.5 1 2]'; % salient values, but transposed
% now we are doing elementwise math with row and col vectors
% our solution is now no longer a vector
% each row of f corresponds to one value of z
% note that doing this directly only works in R2016b or newer
% this could otherwise be done using a loop or bsxfun()
f = r.^2.*sqrt(1+(2*z.*r).^2) ./ sqrt((1+r.^2).^2 + (2*z.*r).^2);
clf
h = plot(r,f); grid on
% in order to get the zeta values in the legend automatically
aa=num2cell(z);
tagfun=@(x) sprintf('\\zeta = %2.2f',x)
legend(h,cellfun(tagfun,aa,'UniformOutput',false),'location','northwest')
xlabel('tony the tiger''s favorite letter')
ylabel('cereal consumed')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/577967/image.png)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!