hello in beginer with matlab and i have a error
Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.
Error in mydelta
>> mydelta
Error: File: mydelta.m Line: 18 Column: 5
Unexpected MATLAB expression.
>> mydelta
Error: File: mydelta.m Line: 18 Column: 5
Unexpected MATLAB expression.
function d=mydelta(k,n1,n2)
n=[-10:10];
x=sqrt(pi)*(mydelta(-10,-20,20)-mydelta(7,-20,20))
figure(1)
stem(n,x)
if n1>n2
disp('Το κατω οριο n1 θα πρεπει να ειναι μεγαλυτερο απο το n2');
return
end
if k>=n1 & k<=n2
d=[zeros(1,k-n1) 1 zeros(1,n2-k)];
else
d=zeros(1,n2-n1+1);
end
n=[‐20:20];
x=sqrt(pi)*(mydelta(‐10,‐20,20)‐mydelta(7,‐20,20))
figure(1)
stem(n,x)

Réponses (1)

Stephen23
Stephen23 le 6 Juin 2016
Modifié(e) : Stephen23 le 6 Juin 2016

0 votes

Your function calls itself, and then inside that it calls itself again, and so on. A function calling itself is called recursion, and is used to solve some kinds of problems efficiently. However you have put nothing in your code to limit how deep this recursion goes, so it just keep on calling itself...
Perhaps:
  • you did not intend to make your function call itself: in this case you need to change your function so that the function name is not used inside the function itself.
  • you intended recursion: in this case you need to add some variable that changes with each recursive call, and use this variable to check when to stop recursion.
Read more about recursion here:

6 commentaires

Vin dimitriadis
Vin dimitriadis le 6 Juin 2016
Modifié(e) : Stephen23 le 6 Juin 2016
im so sorry i copy the code wrong belong is the right form of the code
function d=mydelta(k,n1,n2)
if n1>n2
disp('Το κατω οριο n1 θα πρεπει να ειναι μεγαλυτερο απο το n2');
return
end
if k>=n1 & k<=n2 [n1,n2]
d=[zeros(1,k-n1) 1 zeros(1,n2-k)];
else
d=zeros(1,n2-n1+1);
end
n=[‐20:20];
x=sqrt(pi)*(mydelta(‐10,‐20,20)‐mydelta(7,‐20,20))
figure(1)
stem(n,x)
and i have error on arguments
Vin dimitriadis
Vin dimitriadis le 6 Juin 2016
ignore [n1,n2] it was comments at line 6
Stephen23
Stephen23 le 6 Juin 2016
Modifié(e) : Stephen23 le 6 Juin 2016
  • You claim to "have error on arguments", but you don't show us the error message, so it makes it very hard to diagnose what you are doing.I will guess that you can simply clicking the RUN button in the toolbar/ribbon: in this case MATLAB calls your function without any input arguments, thus the error. Because your function requires three input arguments this causes an error.The solution is simple: call the function properly from the command line (or another script, etc), complete with all of its required arguments.
  • Your function will still call itself recursively without limit. You need to fix this.
x=sqrt(pi)*(mydelta(‐10,‐20,20)‐mydelta(7,‐20,20))
Your function still calls itself.
We have no idea what you're trying to do there, but I can safely say you did not intend recursion (since recursive functions normally don't do plotting as well).
Vin dimitriadis
Vin dimitriadis le 6 Juin 2016
Create a function in the MATLAB which creates a distinct deceleration function . The function will He has three arguments: the k, and the limits of n; returns a vector with the sequence d. Apply the function of development in exercise three to represent graphically sequence below:x(n) = √π * (δ(n + 10)-3δ(n - 7)), -10 ≤ n ≤ 10 this one i m trying to do
Stephen23
Stephen23 le 6 Juin 2016
Modifié(e) : Stephen23 le 6 Juin 2016
You should do these introductory tutorials, which will get you started on how to use MATLAB functions properly (this will help you to write them too):
You might also like to read this:
We have already told you what to look at in your code, and to change how you call the function. Not many people here will simply do your homework for you. This is the hard part where you have to learn new stuff... this might include reading the documentation.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by