Matlab function input problem, can only see 1 root but supposed to see 2 – Noob question

90 Views Asked by At

Thank you for reading this question.

I'm studying numerical methods and I'm using Matlab for the practical parts.

The problem:

I'm supposed to find 2 different roots, y = 0, for positive x, x > 0, with the function below. When I plot it in Matlab I can only see 1. I've checked and changed my code countless times but for the life of me I can't see what I'm doing wrong. Please help, it would be greatly appreciated. Thank you.

To clarify, I'm not asking for help with an algorithm, I only need help with what I'm doing wrong with inputing the function in Matlab. Again, I can only see it having 1 root, y = 0, and not 2, which is the start of the actual problem I am to solve.

The function: $$ f(x) = 98x - \biggl(\frac{x^2 + x + 0.2}{x + 1}\biggr)^9 + 5xe^{-x} = 0 $$

Here is my Matlab code:

x = 0:0.001:1000;

y = 98.*x - ((x.^2 + x + 0.2)./(x + 1)).^9 + 5.*x.*exp(-x);

What am I doing wrong?

Thank you, regards / euro

3

There are 3 best solutions below

0
On BEST ANSWER

If we consider the function $$f(x) = 98x - \biggl(\frac{x^2 + x +\frac 15}{x + 1}\biggr)^9 + 5xe^{-x} $$ $$f(0)=-\frac{1}{1953125}$$ and more than likely a very small root can exist.

Expanding as a Taylor series, we have $$f(x)=-\frac{1}{1953125}+\frac{201171839 }{1953125}x+O\left(x^2\right)$$ Ignoring the higher order terms, then a solution $$x_{est}=\frac{1}{201171839}\approx 4.97087\times 10^{-9}$$

5
On

I think the scale you are plotting at is preventing you from seeing the solution. Try this code

x = -.5:0.001:2;
y = 98.*x-((x.^2+x+ 0.2)./(x+1)).^9 + 5.*x.*exp(-x);
figure;plot(x,y);
grid;
0
On

Sorry for a late update, been busy.

Thank you very much for the input on my problem. You are correct, the scale and step-size I was using was the culprit.

Using this revised code shows that there is indeed a small positive root very close to x = 0.

x = -0.001:1*exp(-10):0.001;
y = 98.*x-((x.^2+x+ 0.2)./(x+1)).^9 + 5.*x.*exp(-x);

figure;plot(x,y);
grid;

axis([ 0.0000000045 0.0000000055 -0.00000001 0.00000001])

Again, thank you very much, regards / euro