basic question on creating a function and plotting
Show older comments
Hello everyone
i have the expression to calculate: Ke=K0*e*a*(a-1)/(1+e-a*e)
K0, e are known values and a is my variable so i create the function Ke(a).
But using the command: Ke1=inline('K0*e*a*(a-1)/(1+e-a*e)') does not apply the given values of K0 and e, that is, it returns the function Ke1(K0,e,a), instead of Ke1(a)
I am using MATLAB 2009b
Thanks in advance
Accepted Answer
More Answers (1)
Amir
on 14 Aug 2014
Please try this code and compare the results:
disp('%%%%% Run1 %%%%%%');
syms K0 e a;
F=K0*e*a*(a-1)/(1+e-a*e);
Ke1=matlabFunction(F)
disp('%%%%% Run2 %%%%%%');
K0=2; e=2.71;
syms a;
F=K0*e*a*(a-1)/(1+e-a*e);
Ke1=matlabFunction(F)
Results are as below:
%%%%% Run1 %%%%%%
Ke1 =
@(K0,a,e)(K0.*a.*e.*(a-1.0))./(e-a.*e+1.0)
%%%%% Run2 %%%%%%
Ke1 =
@(a)(a.*(a-1.0).*(-2.71e2./5.0e1))./(a.*(2.71e2./1.0e2)-3.71e2./1.0e2)
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!