Re: Module and call or others
- To: mathgroup at smc.vnet.net
- Subject: [mg95075] Re: Module and call or others
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Mon, 5 Jan 2009 03:29:15 -0500 (EST)
- References: <gjqa7o$3ej$1@smc.vnet.net>
Hi, a) yx1x2[y_, a_, b_, c_] := Module[{del, ai, bi, ci, x1, x2}, ai = a; bi = b; ci = c - y; del = bi*bi - 4*ai*ci; x1 = (-ai + Sqrt[del])/2/bi; (* <- here you have a "," instead of a ";" *) x2 = (-ai - Sqrt[del])/2/bi ] and "," separate function arguments, ";" glue statements together. b) sure that you don't mean yx1x2 @@@ (Take[#, 4] & /@ yabc) Regards Jens Lai Ngoc Anh wrote: > Dear All, > > I have a table contains 4 column of data and other 2 column to be filled after calculation. > > Supposed my data set is: > 'in[1]:=' yabc = {{5, 1, 12, 3, 1, 1}, {6, 1, 12, 3, 1, 1}, {7, 2, 10, 4, 1, 1}, {8, 2, 10, 4, 1, 1}}; > > I create a Module as: > 'in[2]:=' yx1x2[y_, a_, b_, c_] := Module[{del, ai, bi, ci, x1, x2}, ai = a; bi = b; ci = c - y; del = bi*bi - 4*ai*ci; x1 = (-ai + Sqrt[del])/2/bi, x2 = (-ai - Sqrt[del])/2/bi]; > > Now I can calculate x1, x2 in the Module yx1x2 with first 4 data of 1st row of yabc as: > 'in[3]:=' yx1x2[yabc[[1, 1]], yabc[[1, 2]], yabc[[1, 3]], yabc[[1, 4]]][[-2]] > 'in[4]:=' yx1x2[yabc[[1, 1]], yabc[[1, 2]], yabc[[1, 3]], yabc[[1, 4]]][[-1]] > > I get correct value of x1 and x2 but I receive error message as: > Module::argrx: Module called with 3 arguments; 2 arguments are expected. more... > 'out[3]:='(-1+2*Sqrt(38))/24 > 'out[4]:='(-1-2*Sqrt(38))/24 > > Now I replace column 5 and 6 of table yabc by x1 and x2 of yx1x2 as: > yabc[[All, 5]] = yx1x2[yabc[[All,1]], yabc[[All, 2]], yabc[[All, 3]], yabc[[All, 4]]][[-1]]; > yabc[[All, 6]] = yx1x2[yabc[[All, 1]], yabc[[All, 2]], yabc[[All, 3]], yabc[[All, 4]]][[-2]]; > > I get wrong results of column 5 as all the values are equal to (-1-2*Sqrt(38))/24. I really don't know what is wrong!! > > I want to have a function or a procedure to calculate both x1 and x2 basing on 4 input data and then apply to yabc table with 4 input and 2 output column. I don't know whether the module is suitable for this problem or other one is suitable. Is there any problem with my module yx1x2 and the calling for column 5? > > Could you please tell me how to solve the problem? > Thanks and regards, > > > Lai Ngoc Anh > > > >