MATLAB Answers

what is the problem?

4 views (last 30 days)
Rochelle Abalus
Rochelle Abalus on 28 Nov 2019
Commented: Rochelle Abalus on 28 Nov 2019
Write a program that will implement the function 𝑓(𝑛) = { 𝑛 2 − 7, 𝑛 < 9 𝑓(𝑛 − 10), 𝑛 ≥ 10 where 𝑛 is an integer and 𝑛 ≥ 0. Using your program, graph 𝑓(𝑛) from 𝑛 = 0 to 𝑛 = 99 using stem().
my while loop is not under the else n>=10 what is the problem?
i=0
for n=0:99
if n<9
i=i+1
f(i)=(n.^2 - 7)
elseif n==9
f(n)=NaN
else n>=10
i=i+1
f(i)=(n-10)
while f(i)>9
f(i)=n-10
end
if f(i)<9
i=i+1
f(i)=(n.^2 - 7)
end
end
end

  0 Comments

Sign in to comment.

Answers (1)

Andrei Bobrov
Andrei Bobrov on 28 Nov 2019
f = @(x) 2*(x - (x >= 10)*10) - 7;

  1 Comment

Rochelle Abalus
Rochelle Abalus on 28 Nov 2019
where will i put that

Sign in to comment.

Sign in to answer this question.

Tags