calculate the value by using a formula

How to calculate the error(pls see the attachment-pg1)? (data and formula is written in the attachment) Do i have to use a for loop here? How to solve this problem?

 Accepted Answer

Dou you mean
err=sqrt(sum((M-P).^2)/numel(M));
I guess "i" does not go to infinity but only to 2000 and the data in your file is incomplete and should have 2000 values each (M and P).

7 Comments

Chathu
Chathu on 19 Feb 2015
Edited: Chathu on 19 Feb 2015
@ Michael- thank you so much for your response. I have attached the original data set.
The issue i am having here is something very obvious: i obtained M=104 and P=100 values when i run my code. How can i take off the zeros(Pls look at the M sheet) out of the data set and make 1st value to zero. My purpose here is to make M and P dimensions same. Can you kindly tell me how to overcome this issue?
To remove the zeros:
M(M==0)=[];
But I see only two zeros (7 and 42), so M will still have more elements than P. Also, this means you shift M. Whether this is a problem or not depends on the case.
If you want to ensure to always take the first values, you can use
minL=min(numel(M),numel(P);
and apply it with
err=sqrt(sum(M(1:minL)-P(1:minL).^2)/minL);
This will simply ignore the extra values at the end of your arrays.
Micheal- thank you so much for your response.
You are right, if i remove zeros i am shifting M. I totally forgot that point-my mistake:( but thanks for pointing it out. Can i ask you my qu in different way(sorry, i would have asked it earlier) Suppose i want to:
1)Make 1st M and P value to zero 2) Afterwards,make M and P dimensions same. So then i can calculate the error. Is it possible to do?
If you want to set a value to zero, just do it:
M(1)=0;
In my code above, values at the end of the array are just ignored. If you want to delete values at the end of your data to equalize the size, just do it with
M=M(1:minL);
P=P(1:minL);
The definition of minL is like shown in the previous post.
Chathu
Chathu on 20 Feb 2015
Edited: Chathu on 20 Feb 2015
Michael- thank you so much for your time and effort. Really appreciate your help. I am getting a value(see below) like this. 0.0000e+00 + 4.3938e+12i
I wonder why i am getting an 'i' here? do you have any idea?
err=sqrt(sum((M(1:minL)-P(1:minL)).^2)/minL);
Best wishes
Torsten.
@ Torsten- Perfect !!!
Finally i obtained estimated values for the error. Thank you sooo much. Appreciate it.

Sign in to comment.

More Answers (0)

Tags

No tags entered yet.

Asked:

on 18 Feb 2015

Commented:

on 20 Feb 2015

Community Treasure Hunt

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

Start Hunting!