How to express extremes??

I want to make m.file which show limit. But when I run this m.file, my desktop doesn't stop working.
Please let me know what is wrong in the content below.
clear
function P=limitest(n)
P=(2*n.^3-4*n.+5)/(n.^3+3*n.^2-6)
endfunction
n=1
while limitest(n)-limitest(n-1)<10
n=n+1;
end
disp(limitest(n));
That is my m.file. I want to show limit about (2*n.^3-4*n.+5)/(n.^3+3*n.^2-6), (f(n)-f(n-1)<10, n : natural number)

2 commentaires

Juho
Juho le 16 Avr 2020
I would appreciate it if you teach me what's wrong!!
Stephen23
Stephen23 le 16 Avr 2020
This is not MATLAB code:
endfunction

Connectez-vous pour commenter.

Réponses (1)

Rik
Rik le 16 Avr 2020

0 votes

It is fine to post questions related to GNU Octave, but you need to make sure that your issue is reproducible in Matlab.
It is unclear what your code is intended to do.
Why do you have clear without any code after it? (the function has its own workspace separate from the workspace that clear is working on) In Matlab this could be a nested function, but the outer function is missing and using clear midway a function is strange.
Trying to run your code separately also doesn't work:
P=(2*n.^3-4*n.+5)/(n.^3+3*n.^2-6)
% ^ ^
%.+ doesn't exist and this should be ./
Once those are fixed, it should already exit the loop at n=1:
n=1:100;
P=(2*n.^3-4*n+5)./(n.^3+3*n.^2-6);
P(2)-P(1) % 2.4286

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Produits

Question posée :

le 16 Avr 2020

Réponse apportée :

Rik
le 16 Avr 2020

Community Treasure Hunt

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

Start Hunting!

Translated by