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?

 Akzeptierte Antwort

Michael Haderlein
Michael Haderlein am 18 Feb. 2015

0 Stimmen

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 Kommentare

Chathu
Chathu am 19 Feb. 2015
Bearbeitet: Chathu am 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.
Chathu
Chathu am 19 Feb. 2015
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 am 20 Feb. 2015
Bearbeitet: Chathu am 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?
Torsten
Torsten am 20 Feb. 2015
err=sqrt(sum((M(1:minL)-P(1:minL)).^2)/minL);
Best wishes
Torsten.
Chathu
Chathu am 20 Feb. 2015
@ Torsten- Perfect !!!
Finally i obtained estimated values for the error. Thank you sooo much. Appreciate it.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by