Borrar filtros
Borrar filtros

the piecewise function runs out a weird figure

1 visualización (últimos 30 días)
dcydhb dcydhb
dcydhb dcydhb el 12 de Mzo. de 2019
Editada: Adam Danz el 6 de Jun. de 2022
function codes are as this
function f = myfun(x)
if (x<1);
f=x.^2 ;
else
f=x;
end
end
main program codes are as this
clc;
clear all;
close all;
x=0:0.1:10;
y=myfun(x);
plot(x,y)
a simple figure but a queer figure,why
  1 comentario
Adam Danz
Adam Danz el 12 de Mzo. de 2019
Hint from
doc if
"An expression is true when its result is nonempty and contains only nonzero elements (logical or real numeric)."

Iniciar sesión para comentar.

Respuestas (1)

Voss
Voss el 3 de Jun. de 2022
x=0:0.1:10;
y=myfun(x);
plot(x,y)
function f = myfun(x)
idx = x < 1;
f = zeros(size(x));
f(idx) = x(idx).^2;
f(~idx) = x(~idx);
end

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by