1

Here my code is running fine.In this code I put x=1 but I want to run x from 1 to 100 and for each value of x I want to export the excel file by the name according to x value.like for x=1 it export by Result1, for x=2 export file name should be Result2 and for x=3 by export by name Result3 and so on.

x = 1;
q[z_] := x z + x*15*z^3;
Result1 = List[];
For[i = 0, i <= 21, i++, z = N[1*10^-6 + i*5*10^-8];
  func1 = q[z];
  AppendTo[Result1, {z, func1}]];
Export["  Result1file.xls",   Result1, "XLS"]; 

1 Answers1

1

I have written your code as a function

export[x_] := Module[{q, Result1, func1},
q[z_] := x z + x*15*z^3;
Result1 = List[];
For[i = 0, i <= 21, i++, z = N[1*10^-6 + i*5*10^-8];
func1 = q[z];
AppendTo[Result1, {z, func1}]];
Export["Result"<>ToString[x]<>"file.xls", Result1, "XLS"];
];

And then call the function from 1 to 100.

export[#]&/@Range[100]
mrkbtr
  • 453
  • 2
  • 10
  • I didn't get how x value increment you are controlling.Let's suppose I want x from 0 to 500 with increment by 50 then how we will control this in this code?? – Anita Maheshwari Jul 09 '17 at 03:04
  • The value of x is mapped into the export function using /@ (Map) function. You can change range to Range[0,500,50] to get increment of 50 starting at 0 till 500. – mrkbtr Jul 09 '17 at 16:14
  • Thanku for your kind help but I have one more quary is that I want to use this inside multiple function there this is showing me error SetDelayed::write: Tag Export in Export[P_] is Protected. >> – Anita Maheshwari Jul 10 '17 at 01:49
  • Thank you for your kind help but I have one more quary is that I want to use this inside multiple function there this is showing me error SetDelayed::write: Tag Export in Export[P_] is Protected. >> what is it mean I didn't get.If you can help me to figure out that, that would be a great owner. Thank you once again. – Anita Maheshwari Jul 10 '17 at 01:54
  • The new function that was written was export[x_]. You may be writing it as Export[x_], which is already an in built function. Just choose another name for it and it will be fine. – mrkbtr Jul 10 '17 at 10:20