-3

Variable definitions are as follows:

eBEG=0.;
epBEG=0.;
aNEXT = 0;
eNEXT=0.;
actStrain=0.;
epTRIAL=0.;
sigTRIAL=Range[0];
sigEND=Range[0];

Constant definitions are as follows:

delta=1.; 
inc=0.; 
delta=160.; 
sigu=300.; 
sigy=165.; 
c=sigu-sigy; 
aBEG=0.000001; 
smodulus=70000.; 
edot=0.01; 
maxiter=10.; 
k=0.;
tol=10.^-5; 
Dg=0.; 
dg=0.;

Main code body:

ge[inp_]= sigy + (c *(1- E^(-delta*inp) ));

func[inp1_] :=
(
  eNEXT=inp1; 
  sigTRIAL=smodulus*(eNEXT-epTRIAL); 
  aNEXT=aBEG; 
  f=Norm[sigTRIAL]-(sigy+(c*(1-E^(-delta*aBEG)))); 
  If[f<=0,
    sigEND=sigTRIAL,
    R=f-(dg*smodulus)-ge[aBEG+dg]+ge[aBEG];
    While[Abs[R] > tol && k < maxiter,
      dRG=-E - (c*delta*E^(-delta*(aBEG+dg)));
      Dg=-(dRG^-1)*R;
      dg=dg+Dg;
      R=f - (dg*E) - ge[aBEG+dg] + ge[aBEG];
      k=k + 1;
      dgg=dg];
    sigEND=(1-((dgg*smodulus)/Norm[sigTRIAL]))*sigTRIAL;
    epTRIAL=epTRIAL+(dgg*Sign[sigTRIAL]);
    aBEG=aBEG+dgg]; 
  eBEG=eNEXT; 
  aBEG=aNEXT; 
  sigEND
)

After evaluating I get no errors but when I apply function func to a list strain:

strain = Range[0, 0.1, 0.0001];
func /@ strain

the function just gets mapped without any evaluation.

{func[0.], func[0.0001], func[0.0002], func[0.0003], func[0.0004],(*and so on till last element of strain*)
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
S_Arnav
  • 11
  • 3
  • 2
    Welcome to Mathematica.SE. The code does not produce the errors you report. Please provide a minimal example that stably reproduce the behaviour. Also please include variable and function definitions (e.g. for ge, itr, edot). Evaluate your code with a freshly started kernel. As it is at the momet, it likely will be closed as being too localized and requiring more input from you. – István Zachar Jun 19 '16 at 12:20
  • Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Jun 19 '16 at 13:08
  • This meta Q&A has some tips on copying Mathematica into the site in a more readable form. The lack of indentation makes your code hard to read quickly. – Michael E2 Jun 19 '16 at 13:12
  • It may be possible that you have a hidden (non-printing) character in your notebook that doesn't show up in your post (see (982) for instance). – Michael E2 Jun 19 '16 at 13:20
  • unrelated to the error, but Abs[R]>tol does nothing. perhaps you want && instead of the semicolon there. – george2079 Jun 19 '16 at 14:29
  • 1
    the space between If and its [ may be the issue – george2079 Jun 19 '16 at 14:34
  • @george2079 I tried both the suggestions but none of them made any difference, of course the while condition works now. It didn't help in solving the actual problem. – S_Arnav Jun 19 '16 at 16:53
  • Please put the definition of all variables involved in your code. We cannot help you without them; we can't replicate your issue. – JungHwan Min Jun 19 '16 at 17:03
  • What about changing from Append to AppendTo? – LLlAMnYP Jun 21 '16 at 07:26
  • @LLlAMnYP Yes it works now, I am getting the output correctly for enet11 but for stress11 I am getting a constant value of 70. I would like to verify whether your are getting the same results. Please note I have added dt to constant definition. Add it before you test the code. – S_Arnav Jun 21 '16 at 08:11
  • Sorry, on mobile, that was just an obvious error that wasn't caught by others – LLlAMnYP Jun 21 '16 at 08:31
  • f consistently evaluates to -25.0001 and the f<=0 condition evaluates to True. as a result, sigEND is never updated. Many other similar things, such as eNEXT always being set to the same value. – LLlAMnYP Jun 21 '16 at 08:53
  • I have evaluated your code as revised. I can not reproduce your problem. strain = Range[0, 0.1, 0.0001]; func /@ strain returns {0., 7., 14., 21., 28., ..., 3.25706*10^10, 3.26041*10^10, 3.26376*10^10, 3.2671*10^10, 3.27045*10^10} – m_goldberg Jun 23 '16 at 13:01
  • I see no reason to re-open this question because the new problem the OP has is not reproducible. Suggest the OP revaluate code in a new session with a clean kernel. – m_goldberg Jun 23 '16 at 13:04

1 Answers1

3

This is not a full answer, but the problems I mention below must be corrected before your code can be executed. This is not to say that the code will work even when these problems are solved. Correcting them is a necessary condition, not a sufficient one.

  • The function ge is not defined.
  • Your While has invalid semantics. Perhaps you meant to write

    While[Abs[R] > tol && k < maxiter, 
      dRG = -E - (c*delta*E^(-delta*(aBEG + dg)));
      Dg = -(dRG^-1)*R;
      dg = dg + Dg;
      R = f - (dg*E) - ge[aBEG + dg] + ge[aBEG];
      k = k + 1];
    
  • The variable inc is undefined and can not be incremented with inc++. Even if it were defined, it would have no effect on the control of flow because it is never tested.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
  • It would be very helpful if you can point out exactly how function ge is undefined. I thought a simple function definition required a formal parameter, in this case inp and a function body, in this case sigy + ( c * ( 1-E^(-delta*inp) )). So compound expression doesn't works for multiple test condition for while conditional? But it works for multiple If conditions. – S_Arnav Jun 20 '16 at 05:53
  • @S_Arnav. There is no syntactically correct function definition in your code. Perhaps ge[inp_] := sigy + (c*(1 - E^(-delta*inp))) is what you should have written. To learn how to define functions, follow this link – m_goldberg Jun 20 '16 at 10:00