range in fplot as variables

조회 수: 5 (최근 30일)
Soham Patil
Soham Patil 2021년 12월 7일
편집: VBBV 2021년 12월 7일
clear
clf
clc
syms x y
f=x*y*(x+y);
ylim=[x^2 x];
ylow=ylim(1);
yup=ylim(2);
sol=solve(ylim(1)==ylim(2),x);
a=sol(1);
b=sol(2);
xlim=[a b];
integral=int(int(f,y,ylim(1),ylim(2)),x,xlim(1),xlim(2));
disp('The integral of f in the region enclosed is')
The integral of f in the region enclosed is
disp(integral)
fplot(ylow,[a b])
hold on
fplot(yup)
for p=xlim(1):0.01:xlim(2)
line([p p],subs(ylim,x,p),'Color','#abdbd4')
end
Warning: Error updating ParameterizedFunctionLine.

The following error was reported evaluating the function in FunctionLine update: Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
Error using plot
Vectors must be the same length.
hold off
the job is pretty simple i want to show the regio of integration for a double integral in order dx dy
i have to generalize the above code for any function so that range in fplot should [a b]
although when i run the code it gives me this error
apparently if i give the range as [0 1]
it has no issues
but not all functions will have integrating region in a specific range say [0 5] (default)
why doesn't fplot takes [a b] as the range

채택된 답변

VBBV
VBBV 2021년 12월 7일
편집: VBBV 2021년 12월 7일
clear
clf
clc
syms x y
f=x*y*(x+y);
ylim=[x^2 x]
ylim = 
ylow=ylim(1);
yup=ylim(2);
sol=solve(ylim(1)==ylim(2),x)
sol = 
a=sol(1);
b=sol(2);
xlim=[a b];
I=int(int(f,y,ylim(1),ylim(2)),x,xlim(1),xlim(2));
disp('The integral of f in the region enclosed is')
The integral of f in the region enclosed is
disp(I)
fplot(ylow,[0 5])
hold on
fplot(yup,[0 5]) % specify the same range
axis([0 5 0 5])
for p=xlim(1):0.01:xlim(2)
line([p p],[subs(ylim,x,p)],'Color','red')
end
hold off
figure
for p=xlim(1):0.01:xlim(2)
line([p p],[subs(ylim,x,p)],'Color','red')
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by