How to program a function with 2 variables
조회 수: 1(최근 30일)
Hello, I need to program this as a function (not as an anonymous, but as a function that you can use multiple times in other programs). I can do this when there is only one variables but I really can't do it with 2 variables. Can someone help me?
Thanks in advance
Pranav Verma 2021년 2월 19일
You can write a simple function taking x and k as input and put the conditions as mentioned:
function val = func(x,k)
val = 1;
if (4*k <= x && x < 4*k + 2)
val = 4 - (2 * (x - (4 * k) - 1)^2);
elseif (isinteger(k) && 4*k-2 <= x && x < 4*k)
val = 2 * (x - (4*k) + 1)^2;
Hope this helps!