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
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.
採用された回答
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!