i have problem using streamline in matlab. my problem is i have vector field that compute u,v,x,y from a loop with a specific math function. i use this code to figure vector field :
quiver(x,y,u,v)
and it is get good answer and my answer is converge. but when i want to figure streamline with this code:
startx=-100;
starty=-100;
streamline(x,y,u,v,startx,starty)
i got this error:
Error using griddedInterpolant
Interpolation requires at least two sample points in each dimension.
Error in interp1 (line 183)
F = griddedInterpolant(X,V,method);
Error in stream2 (line 62)
sxi=interp1(xx(:),1:szu(2),sx(k));
Error in streamline (line 62)
verts = stream2(x,y,u,v,sx,sy,options);
Error in (line 44)
streamline(x,y,u,v,startx,starty)
thanks in advance.
Best Regard
Related
I am writing code in MATLAB for convolution and then deconvolution
But when i try to run/simulate, i get following error;
Error using deconv (line 19)
First coefficient of A must be non-zero.
Error in Untitled (line 10)
x1=deconv(y,h)
The code that i am using is as follow:
clc, clear all, close all
t=[0:0.1:36]
h=exp(-2*t).*heaviside(t-1)
x=heaviside(t)-heaviside(t-2)
y=conv(x,h)
plot(y)
xlabel('Time')
ylabel('Amplitude')
title('y(t)=x(t)*h(t)')
x1=deconv(y,h)
How can i get out of this error, as i have to find back input x,by using deconv command which takes two arguments(output y and impulse response h)
I am doing a problem on Hamming code in Matlab. I have generated a bit string of length 1190, for transmission. I am asked to display the string as a curve of step function.
After doing some researched i found that the Heaviside function can be used for display the bit string as unit step curve.
When I use the command fplot(heaviside(l_f),[0 ,10000]), to plot the curve, where l_f is the bit string of length 1190, I get this error
Error using fcnchk (line 106)
FUN must be a function, a valid string expression, or an inline
function object.
Error in fplot (line 60)
fun = fcnchk(fun);
Error in Untitled (line 88)
fplot(heaviside(l_f),[0 ,10000])
When i display using Plot, i.e plot(heaviside(l_f),[0 ,10000]), I get the error
Error using plot Vectors must be the same length.
Error in Untitled (line 88) plot(heaviside(l_f),[0 ,10000])
Anyway to plot the bit string as a curve of step function ?
fplot(heaviside(l_f),[0 ,10000]) won't plot since fplot requires a function as first parameter. But in here it is a matrix. So use plot instead. Next, dimension of heaviside(l_f) will be 1x1190 and dimension of [0 ,10000] is 1x2. So wont work since dimensions are different so use.
x=heaviside(l_f)
y=0:(10000+1)/length(l_f):10000;
plot(x,y);
I am running a MATLAB code which solves a set of non-linear simultaneous equations. The code can be found here. The data input for the code (in excel) can be found here.
I encounter the following error:
Error using sym/subsasgn (line 733)
Indexed assignment to empty SYM objects is supported only in the 0-by-0 case.
Error in Solution (line 69)
x(i,:) = (b(i,1) - b0)./(c(i,1)*x0) + c0/c(i,1);
Does anyone have any idea how I can resolve this?
When declaring a symbolic variable, you have to specify the dimensions, otherwise it's a scalar. Instead of syms x; use sym and set the dimension argument:
x=sym('x',[3,4])
Replace [3,4] with the dimensions you want.
I'm trying to write a script in MATLAB that graphs a function in three dimensions using the mesh function and then finds the maximum of the surface. This is my code so far:
%% Aquifer, 3D maximum search
figure(2)
[X,Y] = meshgrid(-10:.5:10,-10:.5:10);
h = #(x,y)-(1./(1+(x-.25).^2+(y-.5).^2+x+x.*y));
mesh(h(X,Y)) %graph aquifer surface
aquamax = fminsearch(h,[-5;-5])
When I run the code I get this error:
Error using #(x,y)-(1./(1+(x-.25).^2+(y-.5).^2+x+x.*y))
Not enough input arguments.
Error in fminsearch (line 190)
fv(:,1) = funfcn(x,varargin{:});
I've read up on the fminsearch function but I'm not that familiar with it (still a bit of a noob at Matlab). Do I need to rework the code or is it just how I've input things into fminsearch?
Your h function requires 2 scalar inputs, but fminsearch only does one input, possibly a vector. Change h to h = #(x)-(1./(1+(x(1)-.25).^2+(x(2)-.5).^2+x(1)+x(1).*x(2))); and see if that works.
I'm trying to numerically find the solution to X^2+X+C=0 where C is the matrix C=[-6,-5;0,-6] and 0=[0,0;0,0], a quadratic equation where the variable is 2x2 matrix.
So I wrote the following matlab commands
C=[-6,-5;0,-6]
[X1,F,e_flag]=fsolve('X^2+X+C',[1,1;1,1])
where [1,1;1,1] is our initial estimate, or X0.
I'm getting the following errors
"Error using inlineeval (line 15)
Error in inline expression ==> X^2+X+C
Undefined function or variable 'X'.
Error in inline/feval (line 34)
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr,
INLINE_OBJ_.expr);
Error in fsolve (line 218)
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE
cannot continue."
How do I use fsolve to solve these kind of problems?
I don't think fsolve can be used with a string representation of your equation.
You should rather pass a function handle to the solver like this:
C = [-6,-5;0,-6];
[X1,F,e_flag] = fsolve(#(X) X^2+X+C,[1,1;1,1]);
It also depends on what you mean by: X^2. In Matlab this means the matrix product X*X. If you want entry-wise squaring you should use X.^2, in which case you will have four independent quadratic equations, which you could solve independently.