How to write this function in Matlab having inner product
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1696761/image.png)
Here,
inner product is defined as <u,v>=![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1696766/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1696766/image.png)
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 Kommentare
Antworten (1)
William Rose
am 16 Mai 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 Kommentare
William Rose
am 16 Mai 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1696991/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1696996/image.png)
How do you interpret that? It could mean
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1697001/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1697006/image.png)
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.
Siehe auch
Kategorien
Mehr zu Historical Contests finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!