I’m stumped. What is going on with MATLAB’s syntax?
clear all;
dx = .1;
x=-2:dx:2;
f=zeros(length(x),1);
int_f=zeros(length(x),1);
for n=1:length(x)
f(n)=x(n).^2;
int_f(n) = f(n)*dx+int_f(n);
end
plot(x,int_f(n));
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think you should be plotting that using
plot(x,int_f);that way you plot the two arrays rather than one array against one single number.Also your integral step is wrong, it should be
int_f(n) = f(n)*dx+int_f(n-1)except for the first run, where it should beint_f(n) = f(n)*dx