Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

declaration of functions

Status
Not open for further replies.

skjoex

Structural
Joined
Jul 17, 2007
Messages
82
Location
SK
Hi,

I am a new one in Matlab, but I have previous experience from Ansys-APDL and Mathcad. I have a question:

In the attached there are two m-files with declaration of function.

Function Alpha_2(Lambda_1, Lambda_2) works on interval: for Alpha_2(0.4, 0.4) returns correct value and for let us say Alpha_2(6, 0.4) returns NaN value - OK

Function Alpha_1(Lambda_1, Lambda_2) is slight extension of previous one, but it seems that only first statement works.
Alpha_1(0.4, 0.4) returns correct value and for let us say Alpha_1(6, 0.4) returns 2D array - NOT OK. WHY ?

Thank you in addvance.
 
Code which works:

function F1 = Alpha_2(Lambda_1, Lambda_2)
F1 = [8,7,6.4,6,5.5,5,4.75,4.5,4.45]';
F1(1,2) = 0.9625419+(-3.6454601)*Lambda_2*(1+(5.0308278*Lambda_2)^3.0586037)^(-1/3.0586037);
F1(2,2) = 0.9636739+(-2.6572564)*Lambda_2*(1+(3.9919931*Lambda_2)^2.9602062)^(-1/2.9602062);
F1(3,2) = 0.9726341+(-1.9932994)*Lambda_2*(1+(3.2341635*Lambda_2)^2.7782066)^(-1/2.7782066);
F1(4,2) = 0.9496498+(-1.4803090)*Lambda_2*(1+(2.6267325*Lambda_2)^3.1078904)^(-1/3.1078904);
F1(5,2) = 0.9785034+(-1.1933579)*Lambda_2*(1+(2.3203117*Lambda_2)^2.9238812)^(-1/2.9238812);
F1(6,2) = 0.9637229+(-0.7743167)*Lambda_2*(1+(1.9115241*Lambda_2)^2.9607118)^(-1/2.9607118);
F1(7,2) = 0.9946669+(-0.7516043)*Lambda_2*(1+(1.9434759*Lambda_2)^1.9056765)^(-1/1.9056765);
F1(8,2) = 1.2055126+(-3.8888717)*Lambda_2*(1+(7.1149599*Lambda_2)^0.9088292)^(-1/0.9088292);
F1(9,2) = 1.2265766+(-3.2360189)*Lambda_2*(1+(6.2854489*Lambda_2)^1.0927973)^(-1/1.0927973);
F1 = interp1(F1(:,2),F1(:,1),Lambda_1);

Extended previous code which does not work:

function F1 = Alpha_1(Lambda_1, Lambda_2)
F1 = [8,7,6.4,6,5.5,5,4.75,4.5,4.45]';
F1(1,2) = 0.9625419+(-3.6454601)*Lambda_2*(1+(5.0308278*Lambda_2)^3.0586037)^(-1/3.0586037);
F1(2,2) = 0.9636739+(-2.6572564)*Lambda_2*(1+(3.9919931*Lambda_2)^2.9602062)^(-1/2.9602062);
F1(3,2) = 0.9726341+(-1.9932994)*Lambda_2*(1+(3.2341635*Lambda_2)^2.7782066)^(-1/2.7782066);
F1(4,2) = 0.9496498+(-1.4803090)*Lambda_2*(1+(2.6267325*Lambda_2)^3.1078904)^(-1/3.1078904);
F1(5,2) = 0.9785034+(-1.1933579)*Lambda_2*(1+(2.3203117*Lambda_2)^2.9238812)^(-1/2.9238812);
F1(6,2) = 0.9637229+(-0.7743167)*Lambda_2*(1+(1.9115241*Lambda_2)^2.9607118)^(-1/2.9607118);
F1(7,2) = 0.9946669+(-0.7516043)*Lambda_2*(1+(1.9434759*Lambda_2)^1.9056765)^(-1/1.9056765);
F1(8,2) = 1.2055126+(-3.8888717)*Lambda_2*(1+(7.1149599*Lambda_2)^0.9088292)^(-1/0.9088292);
F1(9,2) = 1.2265766+(-3.2360189)*Lambda_2*(1+(6.2854489*Lambda_2)^1.0927973)^(-1/1.0927973);

if (interp1(F1(:,2),F1(:,1),Lambda_1)>=4.45) && (interp1(F1(:,2),F1(:,1),Lambda_1)<=8)
F1 = interp1(F1(:,2),F1(:,1),Lambda_1);
elseif (interp1(F1(:,2),F1(:,1),Lambda_1)<4.45)
F1 = 4.45;
elseif (interp1(F1(:,2),F1(:,1),Lambda_1)>8)
F1 = 8.00;
end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top