I have difficulties with a assiment. De formula dx/dt=-A*t+B is given. The goal is to Plot x(t) between t=0 and t=tmax. A,B,X(0),tmax and dt should be given by the user.
I just can’t get a proper interval in my for…end. To make matter worst it seems that my supervisor wants me to put another formula in the calculation. Which one has to be an analytical solution (= solved “by hand”) together with a numerical solution.
This are my efforts so far. I tried many things. Which are seen in the program with a %
clear all
close all
%dxdt=-A*x+B
%x(t)=(B*t)/(1+A*t)
A=input('give A: ')
B=input('give B: ')
Xo=input('give X(0): ')
X1=input('give X(1): ')
tmax=input('give t maximaal: ')
dt=input('give interval: ')
K=1:dt:tmax;
for t=1:K
X(t)=((-A*Xo+B)*exp(-A*(t-1))-B)/(-A)
T(length(X))=length(X)
end
%T(length(X))=t+1
plot(T,X,'--r')