Re: General--Difficulties in Understanding Mathematica Syntax
- To: mathgroup at smc.vnet.net
- Subject: [mg68941] Re: General--Difficulties in Understanding Mathematica Syntax
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Fri, 25 Aug 2006 05:34:52 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <echdk4$oir$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
madhukarrapaka at yahoo.com wrote: > I am new to Mathematica. The syntax of mathematica is quite different from other programming languages. > I am confused how to use loops like "If",FOR;DO;... Procedural constructs in Mathematica work roughly like in any procedural or object-oriented languages (BASIC, FORTRAN, C, C++, JAVA, PASCAL DELPHI, C#, to name a few). The concepts are the same; the syntax may differ, however. Now, it is utterly better to use high-level constructs such as Map, Thread, Apply, ... when you code in Mathematica. > Here i am giving details of a problem i want to solve. I made an attempt to solve this. Please go thru it and give me necessary corrections. > > Here i am giving the details: > P = 10.3;l = 0.45mm;T = 0.9;r0 = 0.025mm;d = 0.1643mm; > r[xk_, yk_] := (Sqrt[(x - xk)^2 + (y - yk)^2]); > Intensity[xk_, yk_] := (P/(2*Pi*r[xk, yk]*l))*T^(r[xk, yk] - r0); > Imoy=[Integrate[Intensity[xk, yk]],{xk, 0.1, -0.1}, {yk, 0.1, -0.1}] ; > Print[Imoy] > > Then i am getting some value [...] No you don't, since the code displayed above is erroneous and returns error messages if you attempt to execute it. First, correct the syntax. Second, remove the units. Third (a), use NIntegrate since you want numerical answers. Third (b), if you do want a symbolic solution, use exact numbers (0.1 is not the same than 1/10 in terms of precision). Fourth, test individually each function and ask yourself what are and/or where are coming from the values of the variables x and y. For instance, P=10.3; l=0.45; T=0.9; r0=0.025; d=0.1643; r[ xk_?NumericQ, yk_?NumericQ]:= ( Sqrt[ ( x-xk)^2+ ( y-yk)^2]); Intensity[ xk_?NumericQ, yk_?NumericQ]:= ( P/ ( 2*Pi* r[ xk,yk]*l))* T^ ( r[ xk,yk]-r0); Imoy= NIntegrate[ Intensity[ xk,yk]/. { x->1, y->1}, { xk, -0.1,0.1}, { yk, -0.1,0.1}] --> 0.08909421835919498 HTH, Jean-Marc