Can somebody help me please to write the code to fulfill this condition in MATLAB?
4 views (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 28 Sep 2018
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);
Answers (1)
Image Analyst
on 28 Sep 2018
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 Comments
Image Analyst
on 29 Sep 2018
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!