필터 지우기
필터 지우기

Fzero 3 variables 1 equation optimisation

조회 수: 2 (최근 30일)
James
James 2013년 5월 10일
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