How to solve an equation using numerical solver in Matlab?

Hi everyone,
I want to solve this equation using numerical solver. I have value of R and want to calculate the coressponding value of n using numerical solver.
May someone help me here ......
R =1/n^2 [(n+1)ln(n+1)-n]

 Accepted Answer

Look up documentation on fzero.

11 Comments

I have no initial point to solve this ....
>> x = fzero(@(x)x^(-2)*((x+1)*ln(x+1)-x)-0.44999)
Error using fzero (line 118)
The input should be either a structure with valid fields or at least two arguments to FZERO.
Plot a curve of the right hand side Vs n, to see roughly where it equals R.
You need to supply an initial guess. Also MATLAB use log not ln, for log to the base e.
You need to pass the initial guess to fzero as its second argument.
see i guess x=5 but still did not get the answer....
Try
R = 0.44999;
f = @(n) ((n+1).*log(n+1)-n)./n.^2 - R;
n0 = 1; % Initial guess
n = fzero(f,n0);
disp(n)
May you help me in generalizing this programme for large number of values. For example, I have more tahn 500 values of R and I want to calculate n for each values of R ....
But what is wrong with writing a loop? Just wrap that code inside a loop, where you change R each time through.
Earlier my code did not work with the loop but now I have fixed the error... it works perfectly .. Thanks

Sign in to comment.

More Answers (0)

Categories

Asked:

aa
on 30 Sep 2020

Commented:

aa
on 30 Sep 2020

Community Treasure Hunt

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

Start Hunting!