Filter löschen
Filter löschen

range in fplot as variables

5 Ansichten (letzte 30 Tage)
Soham Patil
Soham Patil am 7 Dez. 2021
Bearbeitet: VBBV am 7 Dez. 2021
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

Akzeptierte Antwort

VBBV
VBBV am 7 Dez. 2021
Bearbeitet: VBBV am 7 Dez. 2021
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

Weitere Antworten (0)

Kategorien

Mehr zu Function Creation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by