Azzera filtri
Azzera filtri

Subscript indices must either be real positive integers or logicals.

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

KSSV
KSSV il 7 Dic 2017
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.

Più risposte (0)

Categorie

Scopri di più su Partial Differential Equation Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by