How to write this function in Matlab having inner product
9 views (last 30 days)
Show older comments
Here,
inner product is defined as <u,v>=
Is this is correct?
function F_val = F(wi, ci, Li, K, e, sigma, zi)
% Compute the first term: K <e sum from i to N ci Li, e sum from i to N ci Li>
term1 = K * e^2 * sum(exp(sum(ci .* Li)) .* exp(sum(ci .* Li)));
% Compute the second term: K <e sum from i to N ci Li, -2 sigma>
term2 = K * e * sum(exp(sum(ci .* Li)) * (-2 * sigma));
% Compute the third term: summation i to N e ci <e^wi, wi>
term3 = e * sum(zi .* ci .* exp(wi));
% Compute the final result: F(w) = term1 + term2 + term3
F_val = term1 + term2 + term3;
end
0 Comments
Answers (1)
William Rose
on 16 May 2024
This is a standard definition of inner product for continuous functions. The limits of integration, 0 to 1 in your example, are chosen to be useful in your situation. For a different problem, different limits might be more appropriate.
5 Comments
William Rose
on 16 May 2024
Please provide an example script that calls the function, to demonstrate its use.
Your initial post included a definition of inner product for continuous functions. Is that applicable here? If so, what is the variable of integration, x? Why does it not appear in the equation for F(w)? Your Matab code does not integrate anything from 0 to 1.
Perhaps, as @Torsten suggests, the inner product in this case is the inner product of two vectors. Please clarify.
The equation
uses "e" in multiple places. Are they all the same "e", specifically e=2.718...? If they are different e's, then write the equation differently, for clarity.
The first function inside the first inner product is
How do you interpret that? It could mean
which may be written in Matlab
f1=exp(sum(c.*L.*w));
where c, L, and w are vectors of length N. In this case, f1 will be a scalar, not a vector. And it will be a function of its arguments (ci, Li, wi). The fact that you pass the value e to the function suggests that the first "e" is not e=2.718. An alternative interpretation of the first function inside the inner product is
where I have used e0 for the first "e", for clarity. This may be written in Matlab
f1=e0*sum(c.*L.*exp(w));
In this case, as in th previous interpretation, f1 is a scalar, and is a function of its arguments (ci, Li, wi). The second function inside the first inner product is similar, but also includes a term "hi". The same questions about interpretation apply to that function.
See Also
Categories
Find more on Historical Contests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!