I have two implicit functions as f1(x,y1)=0 and f2(x,y2)=0. Is there any possible way to plot y1/y2 vs x?

조회 수: 10 (최근 30일)
Suppose you have two any form of implicit functions f1(x,y1)=0 and f2(x,y2)=0. You can't write y1, y2 in terms of x explicitely. Then is it possible to plot any function of y1, y2 versus x, in particular y1/y2 vs x?

채택된 답변

Torsten
Torsten 2022년 6월 9일
f1 = @(x,y1) ...; % insert f1
f2 = @(x,y2) ...; % insert f2
f = @(y) [f1(x,y(1)),f2(x,y(2))]
X = 0:0.1:1; % you might change this x-interval
y0 = [1,1]; % you might change this initial guess for y1 and y2
for i = 1:numel(X)
x = X(i);
y = fsolve(f,y0);
z(i) = y(1)/y(2);
y0 = y;
end
plot(x,z)
  댓글 수: 2
Dip
Dip 2022년 6월 9일
It's showing some error.
To check the code, I took very easy function y1=x^3 and y2=x^2.
Expected to plot z=x. But some error is coming.
clc;
f1 = @(x,y1) y1-x^3; % insert f1
f2 = @(x,y2) y2-x^2; % insert f2
f = @(y) [f1(x,y(1)),f2(x,y(2))];
X = 0:0.1:1; % you might change this x-interval
y0 = [1,1]; % you might change this initial guess for y1 and y2
for i = 1:numel(X)
x = X(i);
y = fsolve(f,y0);
z(i) = y(1)/y(2);
y0 = y;
end
Unrecognized function or variable 'x'.

Error in solution (line 4)
f = @(y) [f1(x,y(1)),f2(x,y(2))];

Error in fsolve (line 264)
fuser = feval(funfcn{3},x,varargin{:});

Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.
plot(x,z);
Can you please validate this code by taking any easy example?
Torsten
Torsten 2022년 6월 9일
f1 = @(x,y1) y1-x^3; % insert f1
f2 = @(x,y2) y2-x^2; % insert f2
f = @(x,y) [f1(x,y(1)),f2(x,y(2))];
X = 0:0.1:1; % you might change this x-interval
y0 = [1,1]; % you might change this initial guess for y1 and y2
for i = 1:numel(X)
x = X(i);
y = fsolve(@(y)f(x,y),y0);
z(i) = y(1)/y(2);
y0 = y;
end
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
plot(X,z)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by