Subscript indices must either be real positive integers or logicals.

2 ビュー (過去 30 日間)
alireza amiri
alireza amiri 2017 年 12 月 7 日
回答済み: KSSV 2017 年 12 月 7 日
I have a problem with this code and when i run it, matlab said : Subscript indices must either be real positive integers or logicals. please help me for this (i attached all functions that need for run this program)
clc; clear all; close all;
%2D WAVE EQUATION utt = c^2(uxx+uyy)
%with initial condition u(x,y,0) = sin(p*pi*x)*sin(q*pi*y), 0<x<1 0<y<1
% and boundary conditions u(0,y,t) = u(1,y,t)= u(x,0,t)= u(x,1,t) = 0 t>0
ri = 1;
deltar = 0.01;
deltaz = 0.01;
C = 1;
dx = 0.01;
dy = dx;
sigma = 1/sqrt(2); gamma = 1/sqrt(2); %Courant-Friedrich Stability Condition
dt = sigma*(dx/C);
t = 0:dt:1; x = 0:dx:1; y = 0:dy:1;
u = zeros(length(x),length(y),length(t));
p = 2; q = 1;
u(:,:,1) = transpose(sin(p.*pi.*x))*sin(q.*pi.*y); %u(x,y,0) = sin(p*pi*x)*sin(q*pi*y)
%u(x,y,dt)
for i=2:length(x)-1
for j=2:length(y)-1
z = 1:0.1:2;
for zindex=1:11
n = [0.1,1,10];
for nindex=1:3
u(i, j, 2, z(zindex), n(nindex))= G(z(zindex), n(nindex))/ro(z(zindex), n(nindex))^2*dt^2*((1/deltar^2)*(u(i+1,j,1)-2*u(i,j,1)+u(i-1,j,1))...
+(1/(ri*2*deltar))*(u(i+1,j,1)-u(i-1,j,1))+(1/deltaz^2)*(u(i,j+1,1)-2*u(i,j,1)+u(i,j-1,1))-(1/ri^2)*(u(i,j,1))) + 2*u(i,j,1) - u(i,j,1);
end
end
end
end
  1 件のコメント
KSSV
KSSV 2017 年 12 月 7 日
It is time now to learn about debugging the code. Explore it.

サインインしてコメントする。

採用された回答

KSSV
KSSV 2017 年 12 月 7 日
Problem is in this line:
u(i, j, 2, z(zindex), n(nindex))= G(z(zindex), n(nindex))/ro(z(zindex), n(nindex))^2*dt^2*((1/deltar^2)*(u(i+1,j,1)-2*u(i,j,1)+u(i-1,j,1))...
+(1/(ri*2*deltar))*(u(i+1,j,1)-u(i-1,j,1))+(1/deltaz^2)*(u(i,j+1,1)-2*u(i,j,1)+u(i,j-1,1))-(1/ri^2)*(u(i,j,1))) + 2*u(i,j,1) - u(i,j,1);
RHS works fine for the first step....but the LHS is a problem......check the value of n(nindex) which is the index for LHS..its value is 0.1.....you cannot use fractions, zero and negative numbers as the indices.....you need to think what exactly you want..and what you are trying to achieve.
Learn about debugging the code..it is the good and best practice to get your mistakes and correct them.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMotion Modeling and Coordinate Systems についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by