Need help getting a code to solve for a variable changing in size with a matching number of equations
2 views (last 30 days)
Show older comments
CODE:
clear;
clc;
%Given;
L = 1;
k = 28;
h = 45;
M = 5;
Eqn = zeros(1,M);
T = zeros(1,M);
q_gen = 1*(10^5);
T(1) = -196;
T_infite = 30;
%Loops
m = 2;
while m <= M
X = 0:L/(M-1):L;
if m < M
Eqn(m) = ((T(m-1) -2*T(m) + T(m+1))/(X(m)^2)) * (q_gen/k) == 0;
T(m) = solve(Eqn(m), T);
elseif m == M
Eqn(m) = h*(T_infite - T(1)) + k* ((T(m) - T(m+1))/X) * (q_gen*X/2) == 0;
T(m) = solve(Eqn(m), T);
end
m = m+1;
end
plot(T);
ERROR:
Check for incorrect argument data type or missing argument in call to function 'solve'.
Error in Project (line 21)
T(m) = solve(Eqn(m), T);
0 Comments
Answers (1)
Walter Roberson
on 1 Dec 2022
q_gen = 1*(10^5);
Numeric
T(1) = -196;
That is a specific numeric value.
X = 0:L/(M-1):L;
That is a vector of numeric values. (Note: consider using linspace instead. And move it to before the loop since it does not change.)
Eqn(m) = ((T(m-1) -2*T(m) + T(m+1))/(X(m)^2)) * (q_gen/k) == 0
Everything on the left hand side is numeric, with no symbolic variables at all. This will be a calculated numeric value "==" 0, which is going to immediately evaluate to true or false, not to an equation.
T(m) = solve(Eqn(m), T);
Eqn(m) is numeric and T is numeric. There is no solve() function that accepts two numeric values.
See Also
Categories
Find more on Applications 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!