Message Boards Message Boards

Creating table of 2 different variable and exporting them to single Excel

Posted 2 years ago

I want to put the results (X, and Rn) of the end of this code in a table for X and Rn.they are 2 different variables which don't depend on each other, and plot them with X on x-axis and Rn on y-axis also if possible export both of them in a single Excel file. Kindly I appreciate any help.

ClearAll["Global"]
ClearAll[My`Print]
ClearAll[X1]
SetAttributes[My`Print, HoldAll]
My`Print[args___] := 
 Do[Print[Extract[Hold[args], i, HoldForm], "=", {args}[[i]]], 
     {i, Length[{args}]}]
s = 0.1; c = 0; k = ((1 - a^2)/2)*s^2; h = 10; n = 0.3; a = n/(1 - n); 
p = (-a)*y + 1 - Sqrt[(a*y - 1)^2 - 2*((1/2)*y^2 - a*y - k)]; 
f := (-Exp[-p])*Exp[y]; 
NIntegrate[f, {y, s, -s}]; 
\[Rho] = h/NIntegrate[f, {y, s, -s}]; 
rn = \[Rho]*Exp[s]; rp = \[Rho]*Exp[-s]; \[Delta] = rp - rn; 
My`Print[\[Rho], rn, rp, \[Delta]]
g = -Exp[-((-a)*Log[y/\[Rho]] + 1 - 
       Sqrt[(a*Log[y/\[Rho]] - 1)^2 - 
         2*((1/2)*Log[y/\[Rho]]^2 - a*Log[y/\[Rho]] - 
                       k)])]; 
R = 10; 
X = ({#1, -(h/2) + NIntegrate[g, {y, rn, rn + #1*(\[Delta]/R)}]} & ) /@ 
   Range[R]; 
Rn = ({#1, rn + #1*(\[Delta]/10)} & ) /@ Range[R]; 
TableForm[{X, Rn}]
Export["mfile.xls", {X, Rn}]
Plot[X, Rn]
POSTED BY: Magdy Ismail
2 Replies
Posted 2 years ago

Hi Magdy,

X and Rn are pairs of numbers, the first one seems to be an index. To plot the values of X vs. Rn

XvsRn = Transpose[{Last /@ X, Last /@ Rn}]
ListLinePlot[Callout[#, Round[#, .01], Above, LeaderSize -> 18] & /@ XvsRn
 , Mesh -> All
 , MeshStyle -> Directive[PointSize[Medium], Red]
 , FrameLabel -> (Style[#, Black, 14] & /@ {"X", "Rn"})
 , ImageSize -> 600
 , PlotTheme -> "Detailed"]

enter image description here

To export

XvsRn // Prepend[{"X", "Rn"}] // Export["mfile.xlsx", #] &
POSTED BY: Rohit Namjoshi
Posted 2 years ago

Thank you so much; that was very helpful.

POSTED BY: Magdy Ismail
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract