MATLAB: How to create 1*101 of some integer array

arraymatrix arraynumerical integration

Hi,
Very basic que: I would like to have 1*101 of -4 array. I have to solve an integral numerically
int_0^x -4 dx;
My code is like:
x= linspace(0,1,0.01);
A = zeros(1,101);
..
cumtrapz(x,-4*A);
But the command prompt shows all zeros for cumtrapz which is certainly not.
If I just use :
cumtrapz(x,-4);
it says matrix dimensions must agree. How can I create this array?

Best Answer

Yo have:
A = zeros(1,101);
and then later you have
cumtrapz(x,-4*A);
all elements of A are zero so -4*A is going to be still zero.
change A=zeros(1,101) to A=ones(1,101)
Also as imageAnalyst said, the third argument for linspace is not the spacing so you need to change the code to something like this
x=linspace(0,1,101);
A=ones(1,101);
cumtrapz(x,-4*A);
By the way, are you sure you want to use cumtrapz()? don't you want the output of trapz()?
Related Question