×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

declaration of functions

declaration of functions

declaration of functions

(OP)
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.

RE: declaration of functions

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close