Fzero 3 variables 1 equation optimisation
1 回表示 (過去 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.
0 件のコメント
採用された回答
Matt J
2013 年 5 月 10 日
Why not just do
H=2*(A-Q-P.^3)
8 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!