Can somebody help me please to write the code to fulfill this condition in MATLAB?
조회 수: 4 (최근 30일)
이전 댓글 표시
I have two functions. for example,
f(x) = 3x^2 -2y +5 (plot for x>1); g(x) = 4x^3 - 3x -7;
For f(x), x is variable and y is a arbitrary fixed number. So, by fixing arbitrary 'y', I can have many graphs for f(x) (for instance: if 'y=2' then I can have one graph for f(x), and for 'y= 2.01' I will have other graph). And For g(x), x is a variable. So, I will get only one graph for g(x) for non-negative x.
My goal is to find an unique intersection point 'x_0' between g(x) and f(x) such that,
g(x_0) = c(constant) + minimum(f(x)).
here I can change y arbitrarily in f(x), to get my correct 'x_0'. So, I might need to do iteration here. But I don't know how to write this command. Please help me. Thank you for your time.
댓글 수: 7
Walter Roberson
2018년 9월 28일
Maybe
syms x y
fx = f(x);
solx = solve( diff(fx, x), x );
infimum = subs(fx, x, solx);
soly = solve(c + infimum == g(y), y);
답변 (1개)
Image Analyst
2018년 9월 28일
So, is this what you have:
y = linspace (0, 3, 1000);
gy = 4 * y .^ 3 - 3 * y - 7;
plot(y, gy, 'k-', 'LineWidth', 2);
grid on;
hold on;
ca = {'gy'};
% Next family of equations:
x = linspace(1, 3, 1000);
y = linspace(-12, 10, 13);
for k = 1 : length(y)
fx = 3 * x .^ 2 - 2 * y(k) + 5;
plot(x, fx, '-', 'LineWidth', 2);
ca{k + 1} = sprintf('y = %.2f', y(k));
end
legend(ca, 'location', 'northwest');
fontSize = 24;
xlabel('y, and x', 'FontSize', fontSize);
ylabel('g(y) and F(x)', 'FontSize', fontSize);
and you want the coordinates of the intersections of the curves?
댓글 수: 6
Image Analyst
2018년 9월 29일
Not sure I understand. I thought you said
g(y) = 4y^3 - 3y -7;
I don't know what infimum is - apparently you say it's the minimum of f(x).
So then is gy just c-min(fx) where c is some predefined contant? But then this g(y) would be just a constant, and not at all the same cubic formula for g(y). In fact it would not be a functionof y at all, just a function of f(x) which is a function of x. Actually I don't see why you're making it confusing by having the independent (horizontal) variable be called x sometimes and y other times. This is not standard.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!