0

How to calculate the limit of a function interatively in Matlab, by closer to the given limit value? The accuracy of closing is 10^(-7)

I suppose that that the taylor formula should be used, but don't know how to apply it there.

The function itself is :

The limit is 88. In other words, the assignment is to present limits as series with assigned variables, compute them step-by-step, approach the limits' value with 10^(-7) precision.

example code of task:

syms x;
F=log(1+sin(x))/(sin(4*x));
a=limit(F,x,0);
disp(a)
sum=taylor(F,x,0,'Order',7);
disp(sum)
disp (subs(sum,x,0))

2 Answers 2

4

Calculating it with MATLAB is quite easy, when using the Symbolic Toolbox. The limit function is what you need:

syms x
limit((x^2-9*x-10)/(sqrt(x+6)-4),x,10)

ans = 
    88

If you want to calculate it by hand, you don't need Taylor series, you'll need L'Hopital's rule, which states

l'hopital's rule (image: wikipedia)

This leads to

result

To calculate this in MATLAB, you could use the diff function to get the derivative and do something like

syms x
f(x) = x^2-9*x-10;
g(x) = sqrt(x+6)-4;
r(x) = diff(f(x)) / diff(g(x));
r(10)

ans = 
    88

Well, as we are using MATLAB, we can of course just use Taylor series expansion and let MATLAB do the job. MATLAB has a taylor function which creates the Taylor expansion. As the Taylor expansion is exact around the expansion point and the error increases, the further away you are from that point, it is best to use 10 as expansion point.

syms x
t(x) = taylor((x^2-9*x-10)/(sqrt(x+6)-4),x,10,'Order',6);
t(10)

ans = 
    88
Sign up to request clarification or add additional context in comments.

13 Comments

I know how to calculate it with syms-limit, but the assignment is to use the taylor formula and somehow implement it in the code.
@erkatya90 - What is the "Taylor" formula? Do you mean Taylor series? The Taylor series of the above expression is highly non-trivial.
I added how to calculate it using L'Hospital's rule. This works perfectly for the function you provided. Do you need to use the Taylor series?
@rayryeng yeah, I think that what I mean. The thing is, we must use Taylor series. I calculated how should it look, but don't know what to do next. Anyway, there is an example code of that task, i added it to the question text
@hbaderts, yep, I have to do it.
|
3

OK, now that I know what you're after, what you could perhaps do is use that taylor command and expand about a point that is quite far off from where you want to compute the limit. If we set the expansion point to be where you want to evaluate the limit, no matter what order polynomial you choose, you will get the correct result which is what I'm assuming you're not after.

Start at an expansion point that is far away, then keep incrementally increasing the order of polynomial of the Taylor series until you get your desired accuracy. You don't want to choose an expansion point that is too far away, or you will never get the right answer. As such, I'm going to expand at x = 7.

Something like this:

true_val = 88; %// Define true value
syms x;
f = (x^2-9*x-10)/(sqrt(x+6)-4); %// Define function

order = 2; %// Start with second order
format long g; %// For better formatting
while true %// Keep iterating...

    % // Get Taylor polynomial centered at x = 7 of the current order
    pol = taylor(f, x, 7, 'Order', order);

    %// Evaluate the Taylor series
    val = double(subs(pol, x, 10));

    %// Show the results
    disp(['Order: ' num2str(order)]);
    disp('Result');
    disp(val);

    %// Check to see if we have at least 1e-7 accuracy then break out if yes
    if abs(true_val - val) < 1e-7
        break;
    end

    %// Increment the order by 1
    order = order + 1;
end

This is what I get:

Order: 2
Result
          86.9892652074553

Order: 3
Result
          88.0453290425764

Order: 4
Result
          87.9954798755339

Order: 5
Result
          88.0005926106152

Order: 6
Result
          87.9999105029301

Order: 7
Result
          88.0000147335223

Order: 8
Result
           87.999997429935

Order: 9
Result
          88.0000004672668


Order: 10
Result
          87.9999999123696

6 Comments

Maybe use Taylor's theorem (i.e. include the remainder term ) to upper-bound the error and guarantee it's less than 1e-7? (+1 already)
@LuisMendo - Yes that's what I was about to implement, but the OP wants to see the accuracy increase per addition of a polynomial term... I think that's what they're after, but the latest comment made by the OP in hbadert's post confused me more.
@erkatya90 - OH! ok then lol. Did I do what you wanted correctly?
That's pretty close to what I am asked to do. Thanks!
@rayryeng, I think that nothing should be changed, it just seems the code I need. Thanks a lot!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.