
How can i plot this graph?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Farooq Hussain
le 12 Avr 2020
Commenté : Ameer Hamza
le 13 Avr 2020
for x=0:0.5:5;
if 0<x<2
y=((1+0.5*(1-cos(2*pi*x/5))).^-0.5);
else x>2;
y=1;
end
end
plot(x,y)
0 commentaires
Réponse acceptée
Ameer Hamza
le 12 Avr 2020
Modifié(e) : Ameer Hamza
le 12 Avr 2020
You can use this vectorized version which is usually faster in MATLAB as compared to for loop.
x = 0:0.1:5;
y = (x<2)*((1+0.5*(1-cos(2*pi*x/5))).^-0.5) + (x>=2)*1;
plot(x,y)

12 commentaires
Ameer Hamza
le 13 Avr 2020
You can define it like this
A = @(x) (0<x & x<L).*(1+0.5*(1-cos(2*pi*x/L))-1/2) + (L<x).*1;
f1=@(x,u) u * A(x);
Plus de réponses (1)
Thiago Henrique Gomes Lobato
le 12 Avr 2020
Modifié(e) : Thiago Henrique Gomes Lobato
le 12 Avr 2020
Making y=... substitute the whole array. Try something like this:
x=0:0.5:5;
y = zeros(size(x));
for idx = 1:length(x)
if 0<x(idx) && x(idx)<2
y(idx)=((1+0.5*(1-cos(2*pi*x(idx)/5))).^-0.5);
else x(idx)>2;
y(idx)=1;
end
end
plot(x,y)
0 commentaires
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!