Fzero 3 variables 1 equation optimisation

2 次查看(过去 30 天)
I have this equation:
(P.^3)+(0.5.*H)+Q+(1/sin(H*P))=0
I have this function saved in its own func.m file:
function A = func(x,y)
A = (P.^3)+(0.5.*H)+Q+(1/sin(H*P))
end
So it has 3 variables: P,H,Q and I cannot rearrange it in terms of H.
I need to find out for each combination of (P,Q) i.e. for P from 1 to 5 and Q from 1 to 5 the value of H for which A=0. This should give me a matrix of the 25 H values.
I am aware to use "fsolve" but having problems how to do this.
I have looked on Mathworks help which says to do this:
fun = @cos; % function
x0 = [1 2]; % initial interval
x = fzero(fun,x0)
Though I don't understand how to adapt that first line (with the @) to call my function and how to automatically find the interval.
At the moment what I do is choose a value of P and a value of Q and a range for H. Pass these 3 to the function and get back a list of A values. Look at A values to see where it passes through 0 and then set the corresponding values of H either side as the interval in the second bit of code of the fzero function. This gives me a result. Repeat for the other cominations of (P,Q). This is not the best way to do it I know and it time consuming.
How do I code so that I can put in a range of P and a range of Q, and get back a matrix of H values for which that equation equals zero? The intention is then to plot H in terms of P and Q as axes.

采纳的回答

Matt J
Matt J 2013-5-10
Why not just do
H=2*(A-Q-P.^3)
  8 个评论
Matt J
Matt J 2013-5-11
编辑:Matt J 2013-5-11
I should have included a graph
Why? Are we talking about a different function now? As I explained, it is very easy to understand graphically and analytically where the search intervals are going to lie for the function
(P.^3)+(0.5.*H)+Q+(1/sin(H*P))
James
James 2013-5-11
I'm just getting muddled now. The main point of this question was help with understanding fzero and that is working now.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Optimization 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by