Solve 1-(0.955.^​n)-(0.005.​^n)*(0.995​.^(n-1))*n​-(0.005.^2​)*(0.995.^​(n-2))*n*(​(n-1)/2)= 1/2 numerically with matlab

fh = @(n) 1-(0.955.^n)-(0.005.^n)*(0.995.^(n-1))*n-(0.005.^2)*(0.995.^(n-2))*n*((n-1)/2)- 0.5;
n_solved = fsolve(@fh, n_guess);
when I run it, it doesnot work! I need to find n which is the number of projectiles Any help please? Thank you

Answers (2)

fh(1.2)
Gives an error because:
n((n-1)/2)
is an indexing assignment. I don't know what you want here, but n should not be indexing into itself. Perhaps
n.*((n-1)/2)
?
If so, it works fine:
n_solved = fsolve(fh, pi);
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
n_solved =
15.1631

3 Comments

the answer in the book shows that n = 535
Then I guess that you made a mistake while copying the equation for fh from the book.
Plot your fh and you'll see that the zero at 15.1631 is correct.
Best wishes
Torsten-
The answer is simply wrong, then, or perhaps you've mistyped the problem definition. The function is monotonically increasing and positive in that area...
>> [x;fh(x)].'
ans =
530.0000 0.2516
530.5000 0.2517
531.0000 0.2519
531.5000 0.2520
532.0000 0.2522
532.5000 0.2523
533.0000 0.2525
533.5000 0.2526
534.0000 0.2528
534.5000 0.2530
535.0000 0.2531
535.5000 0.2533
536.0000 0.2534
536.5000 0.2536
537.0000 0.2537
537.5000 0.2539
538.0000 0.2541
538.5000 0.2542
539.0000 0.2544
539.5000 0.2545
540.0000 0.2547
>>

Sign in to comment.

fh=@(n) 1-0.955.^n-0.005.^n.*0.995.^(n-1).*n-0.000025.*0.995.^(n-2).*n.*(n-1)/2- 0.5;
NB: n.*(n-1)/2, not n(n-1)/2

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

on 7 Oct 2015

Edited:

dpb
on 8 Oct 2015

Community Treasure Hunt

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

Start Hunting!