Function & Plot?

조회 수: 1 (최근 30일)
Abdullah Azzam
Abdullah Azzam 2015년 10월 17일
댓글: Steven Lord 2015년 10월 17일
I am trying to solve an example that wants me to solve the equation(c=c-(k*c*t)) and plot the graph between c and t, knowing that t is the step size which in my case is 0.15, and k is constant=0.3, and c=15 initially, I am looking to create a function that calculate the decaying rate with time I have tried the following code: function Decayrate ()
k=0.3;
c=15;
t=(0:0.15:2.1);
c=c-(k*c*t)
plot (t,c)
but the problem is that it when applying the equation the t that going to be used is the the t value and not the step size (0.15), so how can I apply the step size instead of t to the equation, and plot c with t at the same time knowing that at t=0 c=15?
  댓글 수: 1
Eng. Fredius Magige
Eng. Fredius Magige 2015년 10월 17일
Hi t=0, c=0.15 Noted that equation c is implicit? I think you have to use while function as long you known the boundary, (how far it has to go!!!!!!)

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

답변 (1개)

Martin Schätz
Martin Schätz 2015년 10월 17일
From what i did understand, if c=15 initialy, you have to change it every time. so the newc=c-(k*c*t) and also t will change every time. So i thing the code should look like this:
clear all
k=0.3;
c=15;
t=(0:0.15:2.1);
c=zeros(1,15)
Setup initial c to 15
c(1)=15;
for every next c, i will use the previous c and right t
for i=2:15
c(i)=c(i-1)-(k*c(i-1)*t(i))
end
figure
plot(t,c), axis tight
xlabel('t')
ylabel('c')
  댓글 수: 2
Abdullah Azzam
Abdullah Azzam 2015년 10월 17일
guess I couldn't explain the question briefly, let me try again, I have the following equation that I want to solve numerically, dc/dt=-kc then plot the graph between c and t, in your answer c hit the 0 by the time t = 2.1 sec while it should almost be 8.12, is it clear that way?
Steven Lord
Steven Lord 2015년 10월 17일
That statement of your question is much clearer. If you want to solve a differential equation numerically first take a look at ODE45.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by