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

조회 수: 1 (최근 30일)
Greg
Greg 2023년 11월 27일
댓글: Greg 2023년 11월 27일
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에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by