range in fplot as variables

4 次查看(过去 30 天)
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