How to Sum functions?
Mostrar comentarios más antiguos
Hi,
I have an ugly function which I want to integrate it with respect to θ1 and θ2 in a function handle. X and Y are two n*1 arrays. I wonder how can I do the summation so that at the end (before integration) I have the result as sum square of n functions in terms θ1 and θ2? That is, this sum should take values of X and Y from the arrays simultanouesly and plug into y and y^ respectively.
Thanks
σ_f^2≡∫(y-y ̂ )^2 *pdf(θ)dθ
pdf(θ)=exp(-1/(2σ^2 ) *∑(y-y ̂ )^2 )
y=C1-θ1*f(x)-θ2g(x)
y ̂ =Y
7 comentarios
Raghunandan V
el 12 de Mzo. de 2019
I am not able to link with your explanation and the formulas there. Could you please have a better formula. I am not to understand the formula.
ASH
el 12 de Mzo. de 2019
Raghunandan V
el 15 de Mzo. de 2019
I am still not able to understand the question. I am extremely sorry.
From my understanding. I followed your question like this:
step1: calculate y, given θ1 , θ2, f(x), g(x) and c1
step2 : find y^ from Y
step3 : find probability distribution function of θ1 , θ2,
step4 : Integrate the squares
So in what step are you facing difficulty?
ASH
el 15 de Mzo. de 2019
Raghunandan V
el 15 de Mzo. de 2019
Yup! I now understand the problem.I think you got confused with for loop(I am not sure yet) Could you please post your data matrix of all the inputs. I will try to optimize the code. I dont think for loop is required. please post a sample data of X, c1, te1, err and te2
ASH
el 15 de Mzo. de 2019
Raghunandan V
el 15 de Mzo. de 2019
Very interesting situation! I see that the function intergral2 doesn't support any matrices. Have you tried Laplace approach?
Respuesta aceptada
Más respuestas (1)
ASH
el 15 de Mzo. de 2019
0 votos
3 comentarios
Raghunandan V
el 18 de Mzo. de 2019
Hi,
I was out in the weekends. You cannot pass matrices into intergral2 function. As I was telling it creates its own matrix for the limits of integrals.
Coming to your code. I will try to break it down.
V_bi=[24083763.7420230, 1789248958.52452; 1789248958.52452, 154995317706.961];
I think you must be new to coding. You write the formulas correctly but you lack the skills to write it cleanly. Always add comments and do use indentation for coding in for loops. Do read a wonderful article here for good coding guidelines. Assume a third person wanting to understand the problem, he should be reading the code like a story.
for i=1:length(X)
If you see this line. By looking at the way you defined it, I would say this line need not be inside the for loop at all because you are defining it everytime inside the loop. Everytime inside the for loop it defines a new memory location which is time consuming. Only put nthe part of code which you want run multiple times.
The next point I would like to mention is the number of operations you carry out in one line. This is very difficult for people who read it. Industry standard tells that not more than 5 to 6 mathematical operations can exists in one line. break them into smaller peices and then express the equation. I really helps you to debug the errors
func1=@(te1,te2,X,Y)(Y-(c(1)-te1*asinh(c(3)^2*X/(1-X/c(4)))-te2*X)).^2.*exp(-.5*(V_bi(1,1)*(te1-c(2)).^2+2*V_bi(1,2)*(te1-c(2)).*(te2-c(5))+V_bi(2,2)*(te2-c(5)).^2));
I am not sure this works the best. You have done matrix multiplication manually!!! Hahaha. The main purpose of using the Matlab is because it can do Matrix multiplication better than what we do. So try to use matlab as much as possible!.
Sigma_f1=integral2(@(te1,te2)func1(te1,te2,X(i),Y(i)),3.76E-02,4.19E-02,1.72E-04,2.25E-04)/((2*pi)^n*det(V_b))^.5;
Could you please explain what this last line does. I dont feel any use for it!
sig_f1(i)=Sigma_f1(end);
end
ASH
el 18 de Mzo. de 2019
Raghunandan V
el 25 de Mzo. de 2019
Editada: Raghunandan V
el 25 de Mzo. de 2019
I would say the best resource for learning matlab is the Matlab documentation itself
Just read the doc for matlab. This can be obtained by typing :
doc
Please do check the code by Guillaume for the previous question. i asked their help as my code had global variables.
Its often a bad practice to have global variables!
There is a course on coursera which teaches machine learning. I wouldn't recommend to take the complete course but a part of it where he teaches Octave which is very similar to Matlab
the link for the course is https://www.youtube.com/watch?v=39PyhM0LAow&list=PLLssT5z_DsK-h9vYZkQkYNWcItqhlRJLN&index=25
Go through this. It will help you a lot
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

