0
Scilab program has stopped working when excecuting code.

Hello all,

I would like to ask for help in my attemt to re-write a piece of code from Matlab to Scilab.

It was written originally for Matlab in 2014 by my collegue, where it did work fine.

The file is supposed to calculate the average residence time of a polymer in an extruder when subjected at different extrusion speeds.

The original Matlab code is included as image for reference purposes.

I have been trying for 2 days to get it working, but when excecuting, Scilab stops working and closes.. Not sure how to solve that error haha.

Below is the code which has been adjusted by me.

//Residence Time Profiler
//Originally developed by Ype van der Zijpp for Matlab, June 2014
//Adapted by Niels van der Rest for Scilab, August 2020
//Intended for profiling the changes in residence time of a polymer process equipment like e.g. Brabender and spinning lines.
//This simulation is based on assuming plug-flow and calculates the AVERAGE residence time profile (internal volume divided by the throughput)
 
//Setting up parameters in variables
IntVol = 160;                                       //Internal volume in ml
IntDiv = 1000;                                      //Internal volume is later devided in IntDiv sections
CapSS = 0.6229;                                     //Throughput of spinpump in ml per cycle

//Extrusion program
//Spinpump speeds in RPM and lead times in seconds
//These variables are designed to be changed when setting up different extrusion protocols.
Step0 = 15;
Step1 = 1;
Step2 = 2.5;
Step3 = 5;
Step4 = 10;
Step5 = 20;
Step6 = 30;
Step7 = 40;
Step8 = 50;
Step9 = 60;
Step10 = 70;
Lead0 = 1800;
Lead1 = 300;
Lead2 = 300;
Lead3 = 300;
Lead4 = 300;
Lead5 = 300;
Lead6 = 300;
Lead7 = 300;
Lead8 = 300;
Lead9 = 300;
Lead10 = 300;
Steps = [Step0 Step1 Step2 Step3 Step4 Step5 Step6 Step7 Step8 Step9 Step10 0; Lead0 Lead1 Lead2 Lead3 Lead4 Lead5 Lead6 Lead7 Lead8 Lead9 Lead10 0];
//Preparing for simulation
SecVol = IntVol/IntDiv;                             //Volume of a small section of IntVol, in ml
IntVolSec = zeros(1,IntDiv);                        //Array containing internal volume sections
RTP = zeros(1,3);                                      //Array for results (for Scilab, both rows and columns must be adressed) - order = rows,columns.
ExtrTime = 0;                                       //Extrusion time = 0
RowCounter = 0;                                     //
 
//Simulation begins
for Stepcount = 1:1:12                                //Do the following calculations for each individual step.
 Step = Steps(1,Stepcount);                         //Which step are we now?
 Lead = Steps(2,Stepcount);                         //Which lead are we now?
 if Step == 0                                       //Signaling when all steps are taken, what happens if step "0" is reached.
     break; 
 end;                                               //End of "if Step == 0"
 SecTime = 60*SecVol/(Step*CapSS);                  //Time needed to pass SecVol, in sec //Continuation of "for Stepcount = 1:12"
 StepTime = 0;                                      //
 for Counter = 2:$                                  //Calculating profile development in step (for Matlab, % = infinity, while for Scilab, $ = infinity)
  RowCounter = RowCounter + 1;                      //
  RTP(RowCounter,1) = ExtrTime;                     //Transfer data to result array RTP
  RTP(RowCounter,2) = Step;                         //Transfer data to result array RTP
  RTP(RowCounter,3) = IntVolSec(1,IntDiv);          //Transfer data to result array RTP
  for n = IntDiv:-1:2                               //Applying time increase and moving data in array
   IntVolSec(1,n) = IntVolSec(1,n-1) + SecTime;     //
  end;
  IntVolSec(1,1) = 0;                               //
  StepTime = StepTime + SecTime;                    //Time spend in current step
  ExtrTime = ExtrTime + SecTime;                    //Total time spend in simulation
  if StepTime > Lead
    break;
  end;                                              //End of "if StepTime > Lead"
 end;                                               //End of "for Counter = 2:$"
end;                                                //End of "for Stepcount = 1:12"
 


Scilab 12-08-20, 7:14 p.m. Niels
0
Your code involves many user defined function calls which are not shown. Hence there is no way for someone to reproduce the difficulty you have. In any case, there are a number of reasons why the code may be throwing an exception forcing Scilab to close. I suggest you troubleshoot your code for very simple cases. Also, you can print variables that you think may be causing problems. Next you can also disable plotting to see if the source of error is not coming from that part. You can also individually test your userdefined functions for various cases making sure they work as expected.
20-08-20, 11:39 a.m. rupakrokade


0
Thank you rupakrolade for your answer. After reading your comment I again took a day trying to get it and I just got it working :) It seems, among others, Scilab didn't like me using for Counter: = 2:$ I wrongly thought $ meant infinity. Still, %inf doen'st work either so I'm ok with just entering a really large number there. I am always annoyed reading in forums just an: "It worked, thanks" and then as reader still searching for the answer. Therefore I have included the working program for Scilab as a picture in this comment.
21-08-20, 1:29 p.m. Niels


0
hey thankyou so much. This was very helpful Also check out plsBaclinc content writing Baclinc SEO services Gaming SSD
Oops! Looks like spam! Waiting for moderator approval.
09-09-20, 5:56 p.m. ronw1117

Login to add comment
Oops! Looks like spam! Waiting for moderator approval


Log-in to answer to this question.