error: x(2): out of bound 1
    2 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Lakshmikruthiga Ponnusamy
 am 13 Mär. 2019
  
    
    
    
    
    Bearbeitet: KALYAN ACHARJYA
      
      
 am 13 Mär. 2019
            I have code of the following. I did everything I could do, but couldnt overcome this error. 
When I execute the below function I get the error
function [disp_dot]=stage2(x,t)%Stage_2 calculation for displacement and pressure
	m=23.5;						     %Stage_2:From bottom choked till bottom is exhausted; top is exhausted
	ODB=0.122;
	IDB=0.04625;
	g=9.8;
	ODT=0.104;
	IDT=0.042;
	Patm=100000;
	dt=0.0001;						%time increment value
	L=0.11;							%This is the length where adiabatic condition starts in top chamber; the length of the leg of the air distributor
	AT = pi*(ODT^2-IDT^2)/4;
	AB = pi*(ODB^2-IDB^2)/4;
	PT=Patm;
	ODSBD=0.1285;
	IDSBD=0.122;
	ASBD=pi*(ODSBD^2-IDSBD^2)/4;
	ASB=0.00451183;
	AST=0.001267892;
	CFM=840;                %air inflow
	CFMm=CFM*(1/2118.88);
	v=CFMm/AB;
	v=5;
	PST=Patm;
	PSB=Patm;
	PT=Patm;
	LB=0.0259;	%This is the length where bottom chamber becomes adiabatic during upward displacement of the piston
	PBinitial=((PT*AT)+(m*g)+(PST*AST)-(PSB*ASB))/AB;
	KB=PBinitial*(AB*LB)^1.4;
	disp_dot(1) = x(2); 
    disp_dot(2) = (1/m)*((KB*AB/(0.000058402+((ASBD+AB)*x(1))^1.4)-(PT*AT)-(m*g)+(PSB*ASB)-(PST*AST)); %Constant value is from bottom channel 4 in excel
end
0 Kommentare
Akzeptierte Antwort
  KALYAN ACHARJYA
      
      
 am 13 Mär. 2019
        
      Bearbeitet: KALYAN ACHARJYA
      
      
 am 13 Mär. 2019
  
      Issue 1: 
When you defined the function as 
[disp_dot]=stage2(x,t)
There is not role of t function input data t in the function.
Issue 2: 
In the following one parenthesis bracket required at last.
disp_dot(2)=(1/m)*((KB*AB/(0.000058402+((ASBD+AB)*x(1))^1.4)-(PT*AT)-(m*g)+(PSB*ASB)-(PST*AST)));
Now I have defined the function as 
function [disp_dot]=stage2(x)%Stage_2 calculation for displacement and pressure
	m=23.5;						     %Stage_2:From bottom choked till bottom is exhausted; top is exhausted
	ODB=0.122;
	IDB=0.04625;
	g=9.8;
	ODT=0.104;
	IDT=0.042;
	Patm=100000;
	dt=0.0001;						%time increment value
	L=0.11;							%This is the length where adiabatic condition starts in top chamber; the length of the leg of the air distributor
	AT=pi*(ODT^2-IDT^2)/4;
	AB=pi*(ODB^2-IDB^2)/4;
	PT=Patm;
	ODSBD=0.1285;
	IDSBD=0.122;
	ASBD=pi*(ODSBD^2-IDSBD^2)/4;
	ASB=0.00451183;
	AST=0.001267892;
	CFM=840;                %air inflow
	CFMm=CFM*(1/2118.88);
	v=CFMm/AB;
	v=5;
	PST=Patm;
	PSB=Patm;
	PT=Patm;
	LB=0.0259;	%This is the length where bottom chamber becomes adiabatic during upward displacement of the piston
	PBinitial=((PT*AT)+(m*g)+(PST*AST)-(PSB*ASB))/AB;
	KB=PBinitial*(AB*LB)^1.4;
	disp_dot(1)=x(2); 
    disp_dot(2)=(1/m)*((KB*AB/(0.000058402+((ASBD+AB)*x(1))^1.4)-(PT*AT)-(m*g)+(PSB*ASB)-(PST*AST))); %Constant value is from bottom channel 4 in excel
end
When I ran the code  here is the output
>> y1=[1,2]
y1 =
     1     2
>> y=stage2(y1)
y =
    2.0000  -26.1197
Please note in the fuction code x define as 2 length vector, which require x(1) and x(2), that why I have passed the y=[valuue1 value 2] to function
Hope it helps!
2 Kommentare
  KALYAN ACHARJYA
      
      
 am 13 Mär. 2019
				
      Bearbeitet: KALYAN ACHARJYA
      
      
 am 13 Mär. 2019
  
			For the 2nd question, please explain the issue in more generalise and simpler way? Or you can ask the question as new question (new thread), so that others can easily see the question and get the fast answer.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

