Piecewise function graph help
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I'm trying to graph a piecewise function and I already sketched know what the graph should look like. The last segment of the graph should be horizontal and linear from r=120.4 until r=200. Any help would be appreciated!
L=200; d=10; s=30; r1_max=22.36; r2_max=120.4;
r=0:200;
for i=1:length(r)
if r(i) < d
F==0
elseif (r(i) >=d) & (r(i) <=r1_max)
F=(s+2.*sqrt(r.^2-d^2))./(L-s);
elseif (r(i) >= r1_max) & (r(i) <=r2_max)
F=(sqrt(r.^2-d^2)+(L/4))./(L-s);
else
F==1;
end
end
plot(r,F)
0 Commenti
Risposte (4)
Torsten
il 14 Nov 2023
Modificato: Torsten
il 14 Nov 2023
L=200; d=10; s=30; r1_max=22.36; r2_max=120.4;
r=0:200;
for i=1:length(r)
if r(i) < d
F(i)=0;
elseif (r(i) >=d) & (r(i) <r1_max)
F(i)=(s+2.*sqrt(r(i).^2-d^2))./(L-s);
elseif (r(i) >= r1_max) & (r(i) <r2_max)
F(i)=(sqrt(r(i).^2-d^2)+(L/4))./(L-s);
else
F(i)=1;
end
end
plot(r,F)
0 Commenti
Voss
il 14 Nov 2023
Modificato: Voss
il 14 Nov 2023
L=200; d=10; s=30; r1_max=22.36; r2_max=120.4;
r=0:200;
F = zeros(size(r));
for i = 1:numel(r)
if r(i) < d
F(i)=0;
elseif r(i) <= r1_max
F(i)=(s+2.*sqrt(r(i).^2-d^2))./(L-s);
elseif r(i) <= r2_max
F(i)=(sqrt(r(i).^2-d^2)+(L/4))./(L-s);
else
F(i)=1;
end
end
plot(r,F)
axis padded
0 Commenti
madhan ravi
il 14 Nov 2023
F = (r < d) * 0 + ((r >= d) & (r <= r1_max)) .* ((s+2.*sqrt(r.^2-d^2))./(L-s)) + ((r >= r1_max) & (r <= r2_max)) .* ((sqrt(r.^2-d^2)+(L/4))./(L-s)) + (r > r2_max);
plot(r,F)
0 Commenti
Les Beckham
il 14 Nov 2023
Modificato: Les Beckham
il 14 Nov 2023
L = 200;
d = 10;
s = 30;
r1_max = 22.36;
r2_max = 120.4;
r = 0:200;
F = zeros(size(r));
idx = r >= d & r < r1_max; % find indices for the first "piece"
% Note: idx will be true where the condition is met
F(idx) = (s + 2.*sqrt(r(idx).^2 -d^2)) ./ (L-s);
idx = r >= r1_max & r < r2_max; % find indices for second "piece"
F(idx) = (sqrt(r(idx) .^2 - d^2) + (L/4)) ./ (L-s);
idx = r >= r2_max; % find indices for third "piece"
F(idx) = 1;
plot(r, F, '.-')
grid on
xlabel 'r'
ylabel 'F(r)'
0 Commenti
Vedere anche
Categorie
Scopri di più su Graph and Network Algorithms in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!