Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me plot this easy function

Status
Not open for further replies.

markwilest

Newbie level 5
Joined
Feb 12, 2006
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,345
Easy Matlab question

Hi,

I'm new to Matlab and I need to plot the following function

x[n] = 5^|n| , |n|≤12
= 0 , |n|> 12

Please help

Mark
 

Re: Easy Matlab question

here is the code for your problem. you can change the range of the plot by changing range = -15:0.1:15 line (but you must use symmetric range, I mean from -a to +a). The number in the middle (0.1) is the distance between two points (sampling distance). You can aslo change that but use same sampling distance for n and range. If you need a more general case or a solution using for loops, let me know.

range = -15:0.1:15;
size_of_range = size(range);
n = -12:0.1:12;
size_of_n = size(n);
x = zeros(size_of_range(2));
x((size_of_range(2)-size_of_n(2))/2+1:(size_of_range(2)+size_of_n(2))/2) = 5.^(abs(n));
plot(range,x)
 

Re: Easy Matlab question

%One simple way of doing is it like

n=-100:100;
x=0:length(n);

for i=1:length(n)
if abs(n(i))<=12
x(i)=5^n(i);
end
if abs(n(i))>12
x(i)=0;
end
end

plot(x);
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top