Unable to use function in script
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am new to matlab, i created a function file and it is working fine while using in command winow but showing "Not enough input arguments." while using in a script
function [V,A,Up,dV,dA] = VAUt(ct,B,L,r,R,Ach,Ap,N)
B = B*0.0254;
L = L*0.0254;
Ach = Ach*0.00064516;
Ap = Ap*0.00064516;
Vd = 22*(B^2)*L/28;
Vc = Vd/(r-1);
V = Vc*(1+0.5*(r-1)*(R+(1- cosd(ct))-((R^2)-((sind(ct))^2))^0.5));
A = Ach + Ap + 22*B*L*(R+1-cosd(ct)+((R^2)-(sind(ct))^2))/14;
Up = 22*L*N*sind(ct)*(cosd(ct)/(((R^2)-(sind(ct))^2)^0.5)+1)/7;
dV = Vc*(R/2 - cos((pi*ct)/180)/2 - (R^2 - sin((pi*ct)/180)^2)^(1/2)/2 + 1/2);
dA = (11*B*L*((pi*sin((pi*ct)/180))/180 - (pi*cos((pi*ct)/180)*sin((pi*ct)/180))/90))/7;
end
in = [15,14,14,9,6,231,154,1500];
[Vt,At,Upt,dVt,dAt] = VAUt(in);
A = [Vt,At,Upt,dVt,dAt];
for i = 0:1:36
in(1) = i*5;
A(:,:,i) = VAUt(in);
end
0 commentaires
Réponse acceptée
Stephan
le 27 Jan 2019
Modifié(e) : Stephan
le 27 Jan 2019
Hi,
you define an array as input arguments. Matlab interprets your array as one input argument, not as 8 as you think. This is because Matlab accepts vectorized functions, which would accept vectors of every single input argument and would calculate the function for all of them with as many function results as the vector has elements. This saves time and no for loops are needed. But the other side is, that you can not give multiple input arguments the way you do.
Best regards
Stephan
2 commentaires
Stephan
le 27 Jan 2019
Modifié(e) : Stephan
le 27 Jan 2019
ct = 15;
B = 14;
L = 14;
...
[Vt,At,Utp,...] = VAUt(ct,B,L,...)
or you rewrite your function to accept the vector argument for scalar values of all inputs:
function [V,A,Up,dV,dA] = VAUt(in)
% Give values to function
ct = in(1);
B = in(2);
L = in(3);
r = in(4);
R = in(5);
Ach = in(6);
Ap = in(7);
N = in(8);
% calculate results
B = B*0.0254;
L = L*0.0254;
Ach = Ach*0.00064516;
Ap = Ap*0.00064516;
Vd = 22*(B^2)*L/28;
Vc = Vd/(r-1);
V = Vc*(1+0.5*(r-1)*(R+(1- cosd(ct))-((R^2)-((sind(ct))^2))^0.5));
A = Ach + Ap + 22*B*L*(R+1-cosd(ct)+((R^2)-(sind(ct))^2))/14;
Up = 22*L*N*sind(ct)*(cosd(ct)/(((R^2)-(sind(ct))^2)^0.5)+1)/7;
dV = Vc*(R/2 - cos((pi*ct)/180)/2 - (R^2 - sin((pi*ct)/180)^2)^(1/2)/2 + 1/2);
dA = (11*B*L*((pi*sin((pi*ct)/180))/180 - (pi*cos((pi*ct)/180)*sin((pi*ct)/180))/90))/7;
end
Then you can calculate the function in the given form:
A = zeros(1,5,36);
in = [5,14,14,9,6,231,154,1500];
for i = 1:36
in(1) = i*5;
[Vt,At,Upt,dVt,dAt] = VAUt(in);
A(:,:,i) = [Vt,At,Upt,dVt,dAt];
end
Note that i corrected two additional error in your for loop, due to i=0 is not valid and your code leaded to some curios results for A.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Configure Simulation Conditions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!