How to store each iteration of a loop as it's own varible.

2 次查看(过去 30 天)
My current code keeps returning this error message...
Error in indexing (line 936)
R_tilde = builtin('subsref',L_tilde,Idx);
I'm trying to find a way that I can create the interior node equations for a heat transfer problem without having to hard code each equation because 8 nodes isn't so bad to code but 100 would be very cumbersome. Any help here would be greatly appreciated. This is the code I have right now and can't seem to figure out how to create this loop.
clear
close all
clc
format short
syms k h g_dot T_inf L delta_x %symbolic varibles.
T = sym('t',[8,1]);
EQ = sym('eqn',[8,1]);
n = 8;
for i = n-(n-1):1:n
EQ(i) = T(i-1) - 2*T(i) + T(i+1) == -2.8409
end
  2 个评论
Steven Lord
Steven Lord 2023-11-27
Please show the full and exact text of the error message (all the text displayed in red in the Command Window) as that exact text may be useful in determining what's going on and how to avoid the error.
Greg
Greg 2023-11-27
Error in indexing (line 936)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in practice (line 18)
EQ(i) = T(i-1) - 2*T(i) + T(i+1) == -2.8409
Thats the exact message I get back.

请先登录,再进行评论。

采纳的回答

Chunru
Chunru 2023-11-27
syms k h g_dot T_inf L delta_x %symbolic varibles.
T = sym('t',[8,1]);
EQ = sym('eqn',[8,1]);
n = 8;
%for i = n-(n-1):1:n
% if i is from 1 to n as give above, you need to define T(0) and T(n+1).
% The following will defind the eq from i=2 to n-1. You can manully define
% EQ(1) and EQ(n)
for i = 2:1:n-1
EQ(i) = T(i-1) - 2*T(i) + T(i+1) == -2.8409;
end
EQ
EQ = 

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by