Need help getting a code to solve for a variable changing in size with a matching number of equations
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Walter Roberson
2022-12-1
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!