plz find the attachment and
help me in executing this program

4 件のコメント

sixwwwwww
sixwwwwww 2013 年 10 月 14 日
There is not attachment here. Try to attach again
unhappy
unhappy 2013 年 10 月 14 日
plzz check it...now
sixwwwwww
sixwwwwww 2013 年 10 月 14 日
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=');
unhappy
unhappy 2013 年 10 月 14 日
actually iam new to this software.
it should b like complex form like a+ij*b i.e x^2+log(x)*1i

サインインしてコメントする。

 採用された回答

sixwwwwww
sixwwwwww 2013 年 10 月 14 日
編集済み: sixwwwwww 2013 年 10 月 14 日

0 投票

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 件のコメント

unhappy
unhappy 2013 年 10 月 14 日
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...
sixwwwwww
sixwwwwww 2013 年 10 月 14 日
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 2013 年 10 月 14 日
編集済み: unhappy 2013 年 10 月 14 日
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 2013 年 10 月 14 日
編集済み: sixwwwwww 2013 年 10 月 14 日
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
unhappy
unhappy 2013 年 10 月 14 日
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
sixwwwwww
sixwwwwww 2013 年 10 月 14 日
What do you mean by final root? you mean final value of x?
unhappy
unhappy 2013 年 10 月 14 日
編集済み: unhappy 2013 年 10 月 14 日
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..
sixwwwwww
sixwwwwww 2013 年 10 月 14 日
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!
unhappy
unhappy 2013 年 10 月 14 日
thanks..u really helped a lot....how can i find u on net..may b in future i can contact u easily
sixwwwwww
sixwwwwww 2013 年 10 月 14 日
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!
unhappy
unhappy 2013 年 10 月 14 日
thankyou...:)
sixwwwwww
sixwwwwww 2013 年 10 月 14 日
You are welcome
unhappy
unhappy 2013 年 10 月 15 日
編集済み: unhappy 2013 年 10 月 15 日
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
sixwwwwww
sixwwwwww 2013 年 10 月 15 日
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
unhappy
unhappy 2013 年 10 月 15 日
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
unhappy
unhappy 2013 年 10 月 15 日
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
sixwwwwww
sixwwwwww 2013 年 10 月 15 日
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
unhappy
unhappy 2013 年 10 月 15 日
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 ExchangeMathematics についてさらに検索

タグ

タグが未入力です。

質問済み:

2013 年 10 月 14 日

編集済み:

2013 年 12 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by