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

2 visualizaciones (últimos 30 días)
Greg
Greg el 27 de Nov. de 2023
Comentada: Greg el 27 de Nov. de 2023
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 comentarios
Steven Lord
Steven Lord el 27 de Nov. de 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.
Greg
Greg el 27 de Nov. de 2023
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.

Iniciar sesión para comentar.

Respuesta aceptada

Chunru
Chunru el 27 de Nov. de 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
EQ = 

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by