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
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

댓글을 달려면 로그인하십시오.

 채택된 답변

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

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 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..
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 Exchange에서 Mathematics에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

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