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]

 Respuesta aceptada

Alan Stevens
Alan Stevens el 30 de Sept. de 2020
Look up documentation on fzero.

11 comentarios

aa
aa el 30 de Sept. de 2020
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.
aa
aa el 30 de Sept. de 2020
You need to pass the initial guess to fzero as its second argument.
aa
aa el 30 de Sept. de 2020
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)
aa
aa el 30 de Sept. de 2020
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.
aa
aa el 30 de Sept. de 2020
Earlier my code did not work with the loop but now I have fixed the error... it works perfectly .. Thanks

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

aa
el 30 de Sept. de 2020

Comentada:

aa
el 30 de Sept. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by