How can I plot a function with a conditions in a simple way?
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
i want to plot this separated function:

I was able to plot the function graph using this method :
clear all
clc
w1=0:1:5000;
w12=-5000:1:0;
M1=-w1.*(w1-5000);
M12=-w12.*(w12+5000);
plot(w1,M1,'b',w12,M12,'b');
xlabel('w')
ylabel('M')
and all good...
but i tried another simple logic method:
clear all
clc
w=-5000:1:5000;
if(w>=0 && w<=5000)% here i have a problem with "w" -with orange underline
M1=-w.*(w-5000);
else
M1=-w.*(w+5000);
end
plot(w,M1,'b');
xlabel('w')
ylabel('M')
and it's not working...why? what is the problem? there is an option to plot this function with conditions?
this is the error message:
"Operands to the || and && operators must be convertible to logical scalar values.
Error in Untitled15 (line 5)
if(w>=0 && w<=5000)"
Respuestas (1)
madhan ravi
el 19 de Jul. de 2019
w = -5000:5000;
M = -w.*(w-5000) .* (w >= 0 & w <= 5000) +...
-w.*(w+5000) .* (w >= -5000 & w <= 0);
plot(w,M)
1 comentario
ron tzuberi
el 19 de Jul. de 2019
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!