|
Abdalla Mohamed wrote:
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gj6qgl$6v4$1@fred.mathworks.com>...
>> "Abdalla Mohamed" <mangawy_21@hotmail.com> wrote in message <gj6nh1$b0r$1@fred.mathworks.com>...
>>> Hello,
>>>
>>> I want to solve this equation using numerical iteration:
>>>
>>> x= ln ( (A*B - C*x)/C) * D
>>>
>>> Thanks in advance for anyone that helps.
>> One way is to use the Newton-Raphson method. Define f(x) as
>>
>> f(x) = log((A*B-C*x)/C)*D-x
>>
>> Use your knowledge of calculus (or the Symbolic Toolbox) to compute the derivative, f'(x). Then make an initial guess, x(0), and start the iteration
>>
>> x(n+1) = x(n) - f(x(n))/f'(x(n))
>>
>> Keep it going until x(n) converges to some limiting value, and that value will be your solution, since f(x(n)) will necessarily have approached zero.
>>
>> Hint: use a 'while' loop to accomplish this iteration using as its exiting condition whatever your criterion is for convergence.
>>
>> Have you despaired of using the 'lambertw' function? It works pretty well. I've tried it.
>>
>> Roger Stafford
>
>
>
> Hey Rogers,
>
> I wrote this code following ur instructions, given that i am a new user,and i am getting an error:
>
> A=3.9387;
> B=0.099077;
> C=2.5776;
>
> f(x)=log((A-x)/B)*C-x; %% Undefined function or variable 'x'.
> f1(x)=(-C/(A-x))-1;
>
> x(0)= 21.7;
How did you choose this initial value? Did you plot the function f(x)?
Or is this just a typo and you meant 2.17?
With the above values for A, B, and C, assuming you are looking for real
values, the function f(x) is 2.5776*log(39.75392878-10.09315987*x)-x,
and it is defined only when 39.75392878 - 10.09315987 * x < 0.
> n=0:1:10;
> x(n+1) = x(n) - y(x(n))/y1(x(n));
Looks like some typos here: y and y1 should be f and f1, shouldn't they?
Also, note that Roger spoke about a *while* loop and you did not specify
a convergence test (stopping criterion) either.
> Please help me debug this error, and also, is this going to function properly ?
>
> Thanks for your time
Regards,
-- Jean-Marc
|