How to store each iteration of a loop as it's own varible.
2 views (last 30 days)
Show older comments
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 Comments
Steven Lord
on 27 Nov 2023
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.
Accepted Answer
Chunru
on 27 Nov 2023
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
More Answers (0)
See Also
Categories
Find more on Matrix Indexing 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!