Message Boards Message Boards

GROUPS:

Fix the following "If else" loop with NIntegrate?

Posted 4 months ago
531 Views
|
1 Reply
|
1 Total Likes
|

Hi. I made a code for "if else" loop in Mathematica. but it's not giving me the output. will anyone help me in that? the import file used in the code is given in the attachment.

    Co = 7.325 10^-11;
    Vfb = 0.6;
    testing = 
      Import["D:\\Ph.D\\mathematica\\trapz test.xls", {"Data"}][[1, 
        Range[1, 121], {1, 2}]];
    V = Import["D:\\Ph.D\\mathematica\\trapz test.xls", {"Data"}][[1, 
        Range[1, 121], 1]];
tit = {#[[1]], 1 - #[[2]]/Co} & /@ testing;
daba = Interpolation[tit];
If[Vfb > V,
 {NIntegrate[daba[x], {x, #, Vfb}] & /@ V}
 , {NIntegrate[daba[x], {x, Vfb, #}] & /@ V}]

output is this:

 If[{0.6} > {-5., -4.9, -4.8, -4.7, -4.6, -4.5, -4.4, -4.3, -4.2, \
    -4.1, -4., -3.9, -3.8, -3.7, -3.6, -3.5, -3.4, -3.3, -3.2, -3.1, -3., \
    -2.9, -2.8, -2.7, -2.6, -2.5, -2.4, -2.3, -2.2, -2.1, -2., -1.9, \
    -1.8, -1.7, -1.6, -1.5, -1.4, -1.3, -1.2, -1.1, -1., -0.9, -0.8, \
    -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0., 0.1, 0.2, 0.3, 0.4, 0.5,
        0.6, 0.7, 0.8, 0.9, 1., 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 
       1.9, 2., 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3., 3.1, 3.2,
        3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4., 4.1, 4.2, 4.3, 4.4, 4.5, 
       4.6, 4.7, 4.8, 4.9, 5., 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 
       5.9, 6., 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 
       7.}, {(NIntegrate[daba[x], {x, #1, Vfb}] &) /@ 
       V}, {(NIntegrate[daba[x], {x, Vfb, #1}] &) /@ V}]

Thanks

Attachments:
Co = 7.325 10^-11;
    Vfb = 0.6;
    testing = 
      Import["D:\\Ph.D\\mathematica\\trapz test.xls", {"Data"}][[1, 
        Range[1, 121], {1, 2}]];
    V = Import["D:\\Ph.D\\mathematica\\trapz test.xls", {"Data"}][[1, 
        Range[1, 121], 1]];
tit = {#[[1]], 1 - #[[2]]/Co} & /@ testing;
daba = Interpolation[tit];
If[Vfb > V[[50]],
 NIntegrate[daba[x], {x, #, Vfb}] & /@ V, NIntegrate[daba[x], {x, Vfb, #}] & /@ V]
{4.14399, 4.05774, 3.9716, 3.8856, 3.79973, 3.71398, 3.62834, 3.5428, \
3.45739, 3.3721, 3.28697, 3.202, 3.11716, 3.03246, 2.94794, 2.86357, \
2.77937, 2.69537, 2.6116, 2.52801, 2.44457, 2.36137, 2.27839, \
2.19564, 2.11316, 2.03093, 1.94896, 1.86729, 1.78595, 1.7049, \
1.62418, 1.54385, 1.4639, 1.38431, 1.30518, 1.22652, 1.14835, \
1.07075, 0.993778, 0.917464, 0.841892, 0.76716, 0.693377, 0.620636, \
0.549054, 0.478927, 0.410872, 0.345897, 0.285159, 0.229677, 0.180024, \
0.136453, 0.0989801, 0.0672554, 0.0406667, 0.0184875, 0, -0.0155074, \
-0.0286217, -0.0398094, -0.0494886, -0.0578936, -0.0652406, \
-0.0717571, -0.0775415, -0.082727, -0.0874261, -0.0916792, \
-0.0955688, -0.0991007, -0.102323, -0.105321, -0.108068, -0.110609, \
-0.113013, -0.115267, -0.117346, -0.119291, -0.121105, -0.122803, \
-0.124414, -0.125931, -0.127336, -0.128635, -0.129893, -0.131082, \
-0.132178, -0.133232, -0.134207, -0.135112, -0.135987, -0.136807, \
-0.137573, -0.138253, -0.138891, -0.139528, -0.14013, -0.140682, \
-0.1412, -0.1417, -0.142155, -0.142593, -0.143003, -0.143371, \
-0.143713, -0.144011, -0.144298, -0.144574, -0.144796, -0.145009, \
-0.145199, -0.145383, -0.145563, -0.145706, -0.145812, -0.145929, \
-0.146035, -0.146078, -0.146128, -0.146155, -0.146155}
If[Vfb > V[[60]], NIntegrate[daba[x], {x, #, Vfb}] & /@ V, NIntegrate[daba[x], {x, Vfb, #}] & /@ V]
{-4.14399, -4.05774, -3.9716, -3.8856, -3.79973, -3.71398, -3.62834, \
-3.5428, -3.45739, -3.3721, -3.28697, -3.202, -3.11716, -3.03246, \
-2.94794, -2.86357, -2.77937, -2.69537, -2.6116, -2.52801, -2.44457, \
-2.36137, -2.27839, -2.19564, -2.11316, -2.03093, -1.94896, -1.86729, \
-1.78595, -1.7049, -1.62418, -1.54385, -1.4639, -1.38431, -1.30518, \
-1.22652, -1.14835, -1.07075, -0.993778, -0.917464, -0.841892, \
-0.76716, -0.693377, -0.620636, -0.549054, -0.478927, -0.410872, \
-0.345897, -0.285159, -0.229677, -0.180024, -0.136453, -0.0989801, \
-0.0672554, -0.0406667, -0.0184875, 0, 0.0155074, 0.0286217, \
0.0398094, 0.0494886, 0.0578936, 0.0652406, 0.0717571, 0.0775415, \
0.082727, 0.0874261, 0.0916792, 0.0955688, 0.0991007, 0.102323, \
0.105321, 0.108068, 0.110609, 0.113013, 0.115267, 0.117346, 0.119291, \
0.121105, 0.122803, 0.124414, 0.125931, 0.127336, 0.128635, 0.129893, \
0.131082, 0.132178, 0.133232, 0.134207, 0.135112, 0.135987, 0.136807, \
0.137573, 0.138253, 0.138891, 0.139528, 0.14013, 0.140682, 0.1412, \
0.1417, 0.142155, 0.142593, 0.143003, 0.143371, 0.143713, 0.144011, \
0.144298, 0.144574, 0.144796, 0.145009, 0.145199, 0.145383, 0.145563, \
0.145706, 0.145812, 0.145929, 0.146035, 0.146078, 0.146128, 0.146155, \
0.146155}
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