Why isn't this exponential function showing in Maple using implicitplot3d? - maple

Trying to graph the following function:
implicitplot3d(100*exp(-20.4+1.482*x+.399*y+.498*z)/(1+exp(-20.4+1.482*x+.399*y+.498*z)), x = 0 .. 40, y = 0 .. 40, z = 0 .. 15)
I don't see anything wrong with the syntax, and Maple does not produce an error. Simply produces a 3D region with nothing in it.
I did input with(plots):

Related

interval spacing on matlab

Hi I'm new to matlab and programming in general and I was wondering if anyone could tell me whats wrong with my code.
These were my instructions and values
Complete the implementation of the dampedOsc function, which evaluates and plots a graph showing the function y=e-0.8xcos 3x at a
set of points spaced at intervals of 0.1 and ranging from 0 to 3π.
The curve should be displayed using a magenta dotted line with
'pentagram' markers.
and my code:
function y = dampedOsc(x)
fplot(#(x) (exp(-0.8*x)*cos(3*x)),[0 3*pi()],'mp:')
end
All tests passed except this one:
Test 1 (Test that function has been plotted):
Actual value does not have correct size:
expectedSize =
1 95
actualSize =
1 98
Test failed.
I honestly have no idea whats gone wrong, I thought it was because of the lack
of point spaced intervals but I have no idea how to input it.
This is an interesting question, so I'll give it a stab. I would probably do something like this.
function z = dampedOsc(x)
if isvector(x) == 0
return
else
z = zeros(1,length(x));
for n = 1 : length(x)
y = exp(-0.8 .* x(n)) .* cos(3 .* x(n));
z(1,n) = y;
end
end
z
end
Then, calling that dampedOsc function from another script, should give the figure.
plot([0 : 0.1 : (3*pi)],dampedOsc(x),'mp:')
I don't have MATLAB in front of me right now, but I think this should work. If it doesn't, I can fix it. Good luck with your project!

Plotting a function in another .m file

i started programming Matlab the last week and i`ve been trying to plot a function file with no success.
This is my function file (impuls.m). It basicaly should set y = 0 for 0<=x<5 and x>10. y = 5 for 5<=x<=10).
function y = impuls(x)
if ((x>=0 && x<5) || x>10)
y=0;
else if (x>=5 && x<=10)
y=5;
end
end
end
I guess i did it right, because when i test it on my main file (fourierreihe.m) using impuls(1) i get a "0" and when using impuls(7) i get a 5. The problem is when i try to get all resuts for the interval [0 13] and plot them as a rectangular impuls.
I tried using:
impuls([0 13])
But i keep getting the error:
fouhierreihen
Operands to the || and && operators must be convertible to logical scalar values.
Error in impuls (line 3)
if ((x>=0 && x<5) || x>10)
Error in fouhierreihen (line 1)
impuls([0 13])
Shouldnt i be getting something as "ans = 0 0 0 0 0 5 5 5 5 5 5 0 0 0" this as an answer?
So guys, what am i doing wrong? I`ve searched for videos and posts and i cant find the mistake there. How could i possibly plot it for the interval?
Thank you in advance,
Pedro.
As the error message and documentation explain, inputs to the short-circuit logical operators must be scalars. It doesn't really make sense fundamentally trying to robustly short circuit with two arrays of truth values.
You can use logical indexing to accomplish the same task in a vectorized manner. For example:
function y = impuls(x)
y = zeros(size(x)); % Initialize the output array
y(x>=5 & x<=10) = 5; % Condition one
Which returns:
impuls(1) =
0
impuls(7) =
5
impuls([0 13]) =
0 0
impuls(0:13) =
0 0 0 0 0 5 5 5 5 5 5 0 0 0
That your original function works with fplot is a concession from MATLAB's developers. The function documentation repeatedly states that the function being plotted must accept vector inputs (though they don't actually enforce it, apparently):
The function must accept a vector input argument and return a vector
output argument of the same size
Your function doesn't do this, because && and || are scalar operations. However, fplot will revert to calculating function outputs element-by-element (a loop) in the event that the array input fails, throwing the following warning:
Warning: Function fails on array inputs. Use element-wise operators to increase speed.
> In matlab.graphics.function.FunctionLine>getFunction
In matlab.graphics.function.FunctionLine/updateFunction
In matlab.graphics.function.FunctionLine/set.Function_I
In matlab.graphics.function.FunctionLine/set.Function
In matlab.graphics.function.FunctionLine
In fplot>singleFplot (line 223)
In fplot>#(f)singleFplot(cax,{f},limits,extraOpts,args) (line 182)
In fplot>vectorizeFplot (line 182)
In fplot (line 153)
In trialcode (line 1)
My Friend....
Try this:
function y = impulse(t)
if 0
%% Example
t=(0:100)';
y=impulse(t)
plot(t,y);
end
for i=1:length(t)
if ((t(i)>=0 && t(i)<5) || t(i)>10)
y(i,1)=0;
else if (t(i)>=5 && t(i)<=10)
y(i,1)=5;
end
end
end
Note:
the for loop is critical in these cases,
the function impulse could exist anywhere, but your local version prevail,
the y(i,1) retain your vector as columns,
run the section inside the void loop (if 0)
the time is normally used here as variable :)....
hyp.

I calculated the following limit in Matlab and I am getting a piecewise as a result. What does that mean?

I tried to calculate this limit:
syms x c
Relative_forward_error = limit (1/tanh(c*x),x,0)
And I have the following result. I am not good at maths, so can anyone help me with this answer please. The symbol c is a constant.
piecewise(c == 0 | dx == 0, 0, dx ~= 0 & ~in(c, 'real'), -limit((c*dx*(tanh(c*x)^2 - 1))/tanh(c*x), x, 0))
Try plotting tanh(x) or tanh(c*x) in WolframAlpha. Also try plotting 1/tanh(x). According to the plot, what happens to tanh(x) as x goes to zero from the left and from the right?

How to use the trapz function verses the integral function

I have my code working using the integral function but I'm looking to implement it using the trapz function instead.
fc = 5*10^6;
fb = 0.2*10^6;
F = [0:10000:10^7];
Tb = 1/fb;
Sequence = [0 1 0 1 1 0 1 1 1 0 0 0 1 0 1 ];
A = sqrt(9/Tb);
w = 2*pi*fc;
I = zeros(1,length(F));
for counter1 = 1:length(Sequence)
if Sequence ( 1, counter1) == 1
s_of_t = #(t) A*cos(w*t)*exp(-1i*2*pi*t*F);
else
s_of_t = #(t) -A*cos(w*t)*exp(-1i*2*pi*t*F);
end
S_of_f = integral(s_of_t,((counter1-1)*Tb),(counter1*Tb),'ArrayValued', true);
for counter2 = 1:length(S_of_f)
I( 1, counter2) = I(1,counter2)+S_of_f(1,counter2);
end
clear S_of_f s_of_t;
end
figure(1)
plot(F,abs(I));
What I want to do is use the trapz function instead of the integral function like this:
for n = 1 : length(F)
S_of_f(n) = trapz(F,s_of_t);
end
instead of:
S_of_f = integral(s_of_t,((counter1-1)*Tb),(counter1*Tb),'ArrayValued', true);
I am having trouble implementing my code using this function so if you have any advice I'd appreciate it.
Errors include:
Undefined function 'max' for input arguments of type 'function_handle'.
Error in trapz (line 43)
perm = [dim:max(ndims(y),dim) 1:dim-1];
I'm not sure which function handles I'm missing.
(Yes I'm taking the Fourier Transform however my attempts to utilize the FFT function took up way too much memory).
trapz expects a vector of function evaluations, not a function handle, which is what integral expects.
if Sequence ( 1, counter1) == 1
s_of_t = #(t,F) A*cos(w*t).*exp(-1i*2*pi*t*F);
else
s_of_t = #(t,F) -A*cos(w*t).*exp(-1i*2*pi*t*F);
end
for i=1:length(F)
r=linspace(((counter1-1)*Tb),(counter1*Tb),100);
S_of_f(i) = trapz(r,s_of_t(r,F(i)));
end
...
I arbitrarily chose 100 evaluation points for the integral using trapz; you will want to modify this to an appropriate value depending on how you are using this code.

Fill a timeseries plot

I have this piece of code and what i'm trying to do is to fill this function plot that is made with timeseries. I tried full and area methods, but didn't have any success to implement them. I also tried to plot using TP1out to plot instead of TP1, but doing this i lose my ZOH interpolation and the graph become linear. If someone have an idea how to solve this i would be thankful.
TP1out = [1 0 0 1 0];
time = 0:4;
TP1 = timeseries(TP1out,time,'name','task 1');
TP1.DataInfo.Interpolation = tsdata.interpolation('zoh');
plot(TP1), grid on
axis([0 4 0 1.5])
I know it's stupid, but i tried many stuff, like:
>> area(TP1)
Undefined function 'real' for input arguments of type
'timeseries'.
Error in xychk (line 48)
x = real(y); y = imag(y);
Error in area (line 45)
[msg,x,y] = xychk(args{1:nargs},'plot');
>> area(time,TP1)
Error using specgraph.areaseries/set
Array must be numeric or logical.
Error in specgraph.areaseries (line 40)
set(h,args{:})
Error in area (line 83)
h = [h
specgraph.areaseries('YData',datachk(y(:,k)),
...
>> area(time,TP1.Data)
Error using area (line 46)
Inputs must be 2-D.