devi method of finding root
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
plz find the attachment and
help me in executing this program
댓글 수: 4
sixwwwwww
2013년 10월 14일
There is not attachment here. Try to attach again
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=');
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
채택된 답변
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
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...
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
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
2013년 10월 14일
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!
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
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
2013년 10월 14일
thankyou...:)
sixwwwwww
2013년 10월 14일
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
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
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
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
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
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에 대해 자세히 알아보기
태그
아직 태그를 입력하지 않았습니다.
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
