vpasolve won't solve function
5 views (last 30 days)
Show older comments
Hi,
Trying to do a simple thing and vpasolve a function.
A1 = 817.08;
A2 = 1051.38;
A3 = 1267.56;
A4 = 1183.44;
B1 = 4.402229;
B2 = 4.517190;
B3 = 4.617679;
B4 = 4.474013;
x1 = .05;
x2 = .10;
x3 = .40;
x4 = .45;
P = 5;
iterateBubble = @(T) ((x1*(10^(-(A1/T) + B1)))/P) + ((x2*(10^(-(A2/T) + B2)))/P) + ((x3*(10^(-(A3/T) + B3)))/P) + ((x4*(10^(-(A4/T) + B4)))/P)
vpasolve(iterateBubble(T) == 1, T)
However, vpasolve returns an error saying that variable T is not defined, even though I did define the function above.
Any help?
0 Comments
Answers (1)
Walter Roberson
on 4 Apr 2020
A1 = 817.08;
A2 = 1051.38;
A3 = 1267.56;
A4 = 1183.44;
B1 = 4.402229;
B2 = 4.517190;
B3 = 4.617679;
B4 = 4.474013;
x1 = .05;
x2 = .10;
x3 = .40;
x4 = .45;
P = 5;
None of those lines define T
iterateBubble = @(T) ((x1*(10^(-(A1/T) + B1)))/P) + ((x2*(10^(-(A2/T) + B2)))/P) + ((x3*(10^(-(A3/T) + B3)))/P) + ((x4*(10^(-(A4/T) + B4)))/P)
That line does not define a variable named T. Instead, it defines a variable named iterateBubble as a handle to an anonymous function. The anonymous function is passed in a single parameter, which for the purposes of the function body will be referred to as T only within the function body . At the time the anonymous function is executed, whatever value is passed in to the function handle will be used in place of references to T in executing the statement. The effect is similar to if you had written
iterateBubble = @iterateBubble_implementation
function result = iterateBubble_implementation(T)
result = ((x1*(10^(-(A1/T) + B1)))/P) + ((x2*(10^(-(A2/T) + B2)))/P) + ((x3*(10^(-(A3/T) + B3)))/P) + ((x4*(10^(-(A4/T) + B4)))/P);
end
in that in both cases, T is a dummy variable that stands in for the value passed in and does not get assigned to inside the calling workspace.
vpasolve(iterateBubble(T) == 1, T)
That tries to pass the variable T into iterateBubble, and tries to use variable T as the second parameter to vpasolve(), but no variable named T has been created.
You can repair this problem by adding this line above the call to vpasolve:
syms T
0 Comments
See Also
Categories
Find more on Interactive Control and Callbacks 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!