I want to create a function that integrates
2 views (last 30 days)
Show older comments
function H=intCP(A,B,C,D,T1,T2)
syms T
H=A*10^(-3)+B*10^(-5)*T+C*10^(-8)*T^2+D*10^(-12)*T^3;
vpaintegral(H,T1,T2)
end
%%command window
This is the code i wrote
I want to integrate from t1 to t2
intCP
Not enough input arguments.
Error in intCP (line 3)
H=A*10^(-3)+B*10^(-5)*T+C*10^(-8)*T^2+D*10^(-12)*T^3;
intCP(34,45,56,34,566,34)
ans =
-124.62
ans =
(2630622583481433*T^3)/77371252455336267181195264 + (5289050460814003*T^2)/9444732965739290427392 + (9*T)/20000 + 17/500
I dont understand why i get "not enough input argument".
Also, I dont understand why i get two answers.
Thank you
2 Comments
Answers (1)
Steven Lord
on 8 May 2019
Let's address your questions in turn. First, why "Not enough input arguments"?
intCP
Not enough input arguments.
Error in intCP (line 3)
H=A*10^(-3)+B*10^(-5)*T+C*10^(-8)*T^2+D*10^(-12)*T^3;
The line intCP calls your function with no input arguments. This means that the variables A, B, C, D, T1, and T2 that you declare intCP receives as inputs are not created, because there's no data to use to create them. When you try to then use the (non-existent) variable A in defining H, MATLAB realizes that it doesn't exist. Because the root cause of that problem is that you called intCP with not enough input arguments that's what MATLAB reports in the error.
Second, why two answers?
intCP(34,45,56,34,566,34)
ans =
-124.62
ans =
(2630622583481433*T^3)/77371252455336267181195264 + (5289050460814003*T^2)/9444732965739290427392 + (9*T)/20000 + 17/500
You're not really getting two answers. Only the second of those answers is actually returned from intCP. The -124.62 is displayed by intCP because you called vpaintegral(H,T1,T2) without a semicolon to suppress displaying its output. The symbolic expression involving T is the actual return value, because that's what H (the variable you declared as the output argument in the definition of intCP) contained when the function finished executing.
Third, why not a number? The vpaintegral function does NOT change its inputs in any way, shape, or form. H was a symbolic expression involving T when it was passed into vpaintegral and it remains a symbolic expression involving T when vpaintegral returns. If you want intCP to return the number rather than the symbolic expression, store the output of vpaintegral into H (the output argument) so it is what is returned from intCP, not the symbolic expression.
0 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!