Newton-raphson for a specific function
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
Jae Song
2015-9-18
In the following line:
dx= Dc/(J);
if the computation of Dc/(J) is not matrix computation, you need to use ./
Dc./(J)
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!