What is wrong with my MATLAB code? Can someone check it for me..? (Sum of series)

2 ビュー (過去 30 日間)
Fasha Reena
Fasha Reena 2020 年 4 月 16 日
回答済み: Walter Roberson 2020 年 4 月 16 日
I have a problem with MATLAB coding. I'm trying to find the solution for the fractional-order equation. I already found for c0 until c3. Then I want to find sum of series as follow, and m=0,1,...,4. But I got error that said 'Index exceeds matrix dimensions'. Why this happened? And how to fix my code? I hope someone can help me.
clear;
syms x t D n h q
% Parameters needed to solve the equation
p = 0.012; % Proliferation rate (per day)
x0 = 25; % The middle of considered interval (mm)
epsilon = 0.01; % suggest by Ozugurlu
cmax = 62.5; % Carrying capacity of GBM tumour cells
alpha = 1.0; % Fractional derivative order
s = 0;
r = 1;
for m=2:3
c(1) = (1/((sqrt(2*pi()))*epsilon))*exp((-1/2)*(((x-x0)/epsilon)^2)); % Initial concentration (c0)
c(2) = (D/((sqrt(2*pi()))*(epsilon^3))-(D*((x0-x)^2))/((sqrt(2*pi()))*(epsilon^5))-p/((sqrt(2*pi()))*epsilon))*(h*((t^alpha)/(gamma(alpha+1))))*exp((-1/2)*(((x-x0)/epsilon)^2))+((h*p*(t^alpha))/(cmax*2*pi()*(epsilon^2)*(gamma(alpha+1))))*exp((((x-x0)/epsilon)^2)); % c1
d = diff(c(m),x,2);
c(m+1) = (n+h)*c(m)-(h*(t^alpha)/(gamma(alpha+1)))*(D*d+p*c(m)-(p/cmax)*((c(m))^2))
while r<=m
c = c(r)*(q^(r-1))+s;
s = c;
r = r+1;
end
end
disp('sum of series=')
disp(s)

採用された回答

Walter Roberson
Walter Roberson 2020 年 4 月 16 日
inside the while loop you calculate something making use of c indexed at a value. you then store that on top of all of c, making c a scalar. Next time through the loop you try to index c but c is a scalar now.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by