Solution Codes of Ordinary Diferenatial Equation

조회 수: 1 (최근 30일)
zekeriya özkan
zekeriya özkan 2022년 5월 19일
편집: Jan 2022년 5월 21일
I wrote MATLAB codes for
equation with parameter n=450, a= -1.99 and x_0=3/4 as follows.
clc; clear; clear all;
a=-1.99; x0=3/4;
sumxx=[];
k=450;
for p=1:k
T=linspace(p-1,p,101);
sumx=1+a.*T;
for n=0:p-2
sumx=sumx+(a.^2).*(((1+a).^n).*(T-(n+1)));
end
sumx=sumx.*x0;
sumxx=[sumxx,sumx];
clear sumx
end
tt=linspace(0,k,k*101);
plot(tt,sumxx)
grid on
hold on
But with the same parameters and in the equation above at two places division by 4, i couldn't arrange MATLAB codes. Please, help me.
  댓글 수: 2
Jan
Jan 2022년 5월 19일
Sorry, what? You cannot insert "/4" at the two locations? Why not?
zekeriya özkan
zekeriya özkan 2022년 5월 21일
When i did your saying, MATLAB generates very different graph. Since it must be very same to first codes graph. Because of this, i asked here how i can correct this different graph?

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2022년 5월 21일
편집: Jan 2022년 5월 21일
What is the purpose of the outer loop "for p=1:k"? Why does the inner loop "for n=0:p-2" run from 0 to p-2?
It is confusing that you've swapped n and k.
The purpose of your code is not clear to me. I have no idea, why inserting /4 twice is a problem and why you assume, that the graph is "not correct". I cannot guess what you expect instead.
n = 450;
a = -1.99;
x0 = 0.75;
T = linspace(0, 1000, 1000);
X = 1 + a * T;
for k = 0:n
X = X + a^2 * (1 + a / 4)^k * (T - (k + 1) / 4);
end
X = X * x0;
figure;
plot(T, X)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by