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 Comments

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

Sign in to comment.

Answers (1)

Rik
Rik on 16 Apr 2020
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

Categories

Products

Asked:

on 16 Apr 2020

Answered:

Rik
on 16 Apr 2020

Community Treasure Hunt

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

Start Hunting!