devi method of finding root

plz find the attachment and
help me in executing this program

4 Comments

There is not attachment here. Try to attach again
plzz check it...now
I have few questions here:
  • Why you defining symbols when you are not using them
syms a b
x = a + 1j * b
  • What user can input in this line: (give some example input)
f = input('enter function in terms of x=');
actually iam new to this software.
it should b like complex form like a+ij*b i.e x^2+log(x)*1i

Sign in to comment.

 Accepted Answer

sixwwwwww
sixwwwwww on 14 Oct 2013
Edited: sixwwwwww on 14 Oct 2013
Dear Unhappy, here is the solution if I understood your problem correctly:
syms a_sym b_sym
x_sym = a_sym + 1j * b_sym;
a = 1;
b = 2;
e = 2.71828;
tol = 1e-5;
da = e + a;
db = e + b ;
count = 0;
while (~(abs(da) < tol) && ~(abs(db) < tol))
f = double(subs(x_sym, [a_sym b_sym], [a b]));
realF = real(f);
imagF = imag(f);
da = (realF * realF + imagF * imagF) / abs(f^2);
db = (realF * realF - imagF * imagF) / abs(f^2);
a = a - da;
b = b - db;
count = count + 1;
if (count > 400)
fprintf('Error...! Solution not converging !!! \n'); % printing the error message
break;
end
end
if (count < 400)
fprintf('The solution = ');
fprintf('\nNumber of iteration taken = %d\n',count);
end

18 Comments

thanks for your solution ....but here i cant enter the i/p(i.e f)...and da = ((real(f)*real(diff(eval(f,1))))+(imag(f)*imag(diff(eval(f,1)))))/abs(eval(diff(f,1)^2));
db= ((real(f)*imag(diff(eval(f,1))))-(imag(f)*real(diff(eval(f,1)))))/abs(diff(eval(f,1)^2));
its differentiation of f(x) with respective x...
what is i/p(i.e f)? Also
diff(eval(f,1)) you mean you want to differentiate f with respect to x?
unhappy
unhappy on 14 Oct 2013
Edited: unhappy on 14 Oct 2013
yup ...and this is the source where i got this method ..."Metal Waveguides for Multi-Axial Light Guiding at Nanometer Scales" and from page no 39 u can find this method...its a small topic
sixwwwwww
sixwwwwww on 14 Oct 2013
Edited: sixwwwwww on 14 Oct 2013
Here is the code:
syms f_sym x
f_sym = eval(input('Input function in terms of x:', 's'));
a = 1;
b = 2;
e = 2.71828;
tol = 1e-5;
da = e + a;
db = e + b;
count = 0;
x_val = input('Input initial value of x: ');
while (~(abs(da) < tol) && ~(abs(db) < tol))
diffF_sym = diff(f_sym, 1);
f = double(subs(f_sym, x, x_val));
diffF = double(subs(diffF_sym, x, x_val));
realF = real(f);
realdiffF = real(diffF);
imagF = imag(f);
imagdiffF = imag(diffF);
da = (realF * realdiffF + imagF * imagdiffF) / abs(diffF^2);
db = (realF * imagdiffF - imagF * realdiffF) / abs(diffF^2);
x_val = x_val - f / diffF;
a = a - da;
b = b - db;
count = count + 1;
if (count > 400)
fprintf('Error...! Solution not converging !!! \n');
break;
end
end
if (count < 400)
fprintf('The solution = ');
fprintf('\nNumber of iteration taken = %d\n',count);
end
I have tried it for input: x^2+log(x)*1j and it is working fine now. You can check once by yourself as well
thanks sir/mam.it works..but my final destination is to find root of analytical soluitons..but here in this i can get only no of iteration it taken.. i cant see final root
What do you mean by final root? you mean final value of x?
unhappy
unhappy on 14 Oct 2013
Edited: unhappy on 14 Oct 2013
yes....it's like you heard about newton raphson method for root finding... this method is similar one for finding roots..but more advantageous than newton one..
So here is your final code:
syms f_sym x
f_sym = eval(input('Input function in terms of x: ', 's'));
a = 1;
b = 2;
e = 2.71828;
tol = 1e-5;
da = e + a;
db = e + b;
count = 0;
x_val = input('Input initial value of x: ');
while (~(abs(da) < tol) && ~(abs(db) < tol))
diffF_sym = diff(f_sym, 1);
f = double(subs(f_sym, x, x_val));
diffF = double(subs(diffF_sym, x, x_val));
realF = real(f);
realdiffF = real(diffF);
imagF = imag(f);
imagdiffF = imag(diffF);
da = (realF * realdiffF + imagF * imagdiffF) / abs(diffF^2);
db = (realF * imagdiffF - imagF * realdiffF) / abs(diffF^2);
final_x = x_val;
x_val = x_val - f / diffF;
a = a - da;
b = b - db;
count = count + 1;
if (count > 400)
fprintf('Error...! Solution not converging !!! \n');
break;
end
end
if (count < 400)
fprintf('The solution = ');
fprintf('\nNumber of iteration taken = %d\n',count);
fprintf(strcat('The root is ', num2str(final_x), '\n'));
end
If you like this answer then accept the answer to help others finding the solution if they have such problem as well. Good luck!
thanks..u really helped a lot....how can i find u on net..may b in future i can contact u easily
I answer here with the same nick. You can post your questions here if I will have answer to that I will reply. Also accept this answer. Good luck!
thankyou...:)
You are welcome
unhappy
unhappy on 15 Oct 2013
Edited: unhappy on 15 Oct 2013
hello mam/sir.. if u could help me finding code for multilayer method in paper"Confinement loss evaluation based on a multilayer division method in Bragg fibers" small topic i.e (2)..i would be thankful...hoping a posiive response from you
Can you tell what should be done because probably I will not be able to understand the physics. May be you can create your code roughly as before and post here as a new question then anybody who will know will help you
i hope u downloaded the paper..basically it is elecromagnetics i.e EM wave equations...and here in this paper if u read carefully u might b come across hankel functions..which is higher order bessel functions...eqations 3,6,10,14 should b implemented..if equation 3 is implemented rest is eazy
here EM wave should b initialized(1a,1b),equation 3 should b implemented,rest is simple like multiplication,inverse..etc..if u have time read upto equation 15...u can clearly understand this
I read it. It is very complicated. Can you tell me what are the inputs and what are the outputs so that I can give you some idea. Also see the following link for initial considerations of Hnakel transform: http://www.mathworks.com/help/matlab/ref/besselh.html
ok..i knew its complicated...but once have a look in "theory of bragg fibers". you can get some idea....here outputs are Ai,bi,Ci,Di i.e in eq=14 in "multilayer method"

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

No tags entered yet.

Asked:

on 14 Oct 2013

Edited:

on 6 Dec 2013

Community Treasure Hunt

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

Start Hunting!