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 comentarios

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

Iniciar sesión para comentar.

Respuestas (1)

Rik
Rik el 16 de Abr. de 2020

0 votos

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

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 16 de Abr. de 2020

Respondida:

Rik
el 16 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by