devi method of finding root
显示 更早的评论
plz find the attachment and
help me in executing this program
4 个评论
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
采纳的回答
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 个评论
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?
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
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?
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
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"
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
标签
尚未输入任何标签。
另请参阅
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
