I need help having my function display both outputs

I am really frustrated in trying to find the answer to this question. I have written a function that creates an upper and lower limit using the same inputs. When I call the function I want it to display both the upper and lower limit. In all the searching I've done nobody answers this clearly enough. I need to see it done with MY function so that I can understand what all these explanations are trying to say.
function [Eupper Elower]=HS(Vr,Gm,Gr,Em,Er,vm,vr);
Vm=1-Vr;
Km=Em/(3*(1-(2*vm)));
Kr=Er/(3*(1-(2*vr)));
Klower=Km+(Vr/((1/(Kr-Km))+((3*Vm)/((3*Km)+(4*Gm)))));
Glower=Gm+(Vr/((1/(Gr-Gm))+((6*Vm*(Km+(2*Gm)))/(5*Gm*((3*Km)+(4*Gm))))));
Elower=(9*Klower*Glower)/((3*Klower)+Glower);
Kupper=Kr+(Vm/((1/(Km-Kr))+((3*Vr)/((3*Kr)+(4*Gr)))));
Gupper=Gr+(Vm/((1/(Gm-Gr))+((6*Vr*(Kr+(2*Gr)))/(5*Gr*((3*Kr)+(4*Gr))))));
Eupper=(9*Kupper*Gupper)/((3*Kupper)+Gupper);
end
When I call on the function I want to see it give me a result [Eupper, Elower]. Please do it to my code instead of trying to explain it, I am very frustrated trying to understand the explanations on here.
Thank you so much for your help.

 Accepted Answer

Birdman
Birdman on 18 Apr 2018
Edited: Birdman on 18 Apr 2018

When I call it as follows:

 [Eupper ,Elower]=HS(5,3,7,6,2,5,4) %inputs are random

it gives me both output.

4 Comments

Is it because when I called for the function I did not assign the results?
Hashin_Shtrikman(0.28,16.97e9,338.7e9,43.99e9,756.8e9,0.305,0.04472)
That is how I was calling for it, so in the explanations they must have meant during the actual use of the function you need to assign it to a variable?
"Is it because when I called for the function I did not assign the results?"
"...in the explanations they must have meant during the actual use of the function you need to assign it to a variable?"
Yes, that is correct. If you do not assign any output arguments then the first one is assigned to the default ans, and any remaining output arguments are ignored. If you want to do any work with the output arguments (e.g. display them, or do calculations on them) then you need to call the function and explicitly define all of the output arguments that you need.
Note that how to call functions with multiple output arguments is explained in the introductory tutorials, which are highly recommended for all beginners (and you could have saved yourself some frustration):
Ok thank you guys so much, I spent about an hour on that trying to figure out the problem. Much appreciated!

Sign in to comment.

More Answers (0)

Asked:

on 18 Apr 2018

Edited:

on 18 Apr 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!