Effacer les filtres
Effacer les filtres

Newton-raphson for a specific function

3 vues (au cours des 30 derniers jours)
Emil G. P. Stender
Emil G. P. Stender le 18 Sep 2015
I would like to use Newton raphson to solve the following equation:
(([L]_0*(1-injectvol/V)^n )-([M]_0*(1-(1-injectvol/V)^n ))*x )*(N-l*x )^l-k*x*(N-(l-1) x )^(l-1)=0.
where [L]_0, [M]_0, injectvol and V are known constants, n is a known variable and assuming values of N, k and l which are also constants.
With the following script:
dx=1; % Change in variable is set to a high value
x=input('Enter the initial estimate -> '); % Initial estimate
iter = 0; % Iteration counter
disp('iter Dc J dx x') % Heading for result
while abs(dx) >= 0.000001 && iter < 100 % Test for convergence
iter = iter + 1; % No. of iterations
Dc=(((L*(1-0.000006/0.000950)^(n))-(M*(1-(1-0.000006/0.000950)^(n)))*x)*(N-l*x)^(l)-k*x*(N-(l-1)*x)^(l-1)); % Residual
J = diff(Dc,x); % Derivative
dx= Dc/(J); %Change in variable
x=x+dx; % Successive solution
fprintf('%g', iter), disp([Dc, J, dx, x])
end
I keep getting an error:
Error in newtontest (line 9)
dx= Dc/(J); %Change in variable
can anyone help me with what is wrong?
best regards: Emil Stender

Réponses (2)

Jae Song
Jae Song le 18 Sep 2015
In the following line:
dx= Dc/(J);
if the computation of Dc/(J) is not matrix computation, you need to use ./
Dc./(J)

Emil G. P. Stender
Emil G. P. Stender le 25 Sep 2015
Many thanks that worked

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by