I'm trying to plot the output angular velocity of a Universal Joint relative to it's input angel which I call phi (in the link above phi= landa_1).
I'm using MATLAB to do this
please note the translations of the notation in the link and my code that is:
beta=Beta, phi=landa_1, Omega_2=Omega_B, Omega_1=Omega_A
here is my code:
clear all, close all, clc
phi=0:360; % one rotation of the input shaft
Beta=60;
Omega_A=1;
Omega_B=(Omega_A*cos(Beta))./(1-((sin(Beta))^2)*((cos(phi)).^2))
plot(phi,Omega_B,'LineWidth',2), grid on
BUT! the plot is not what it should look like (which is available in the link above)
My current plot
You need to convert degree to radian in order to use sin and cos. So
clear all, close all, clc
phi=0:360; % one rotation of the input shaft
Beta=60;
Omega_A=1;
Omega_B=(Omega_A*cos(Beta/180*pi))./(1-((sin(Beta/180*pi))^2)*((cos(phi/180*pi)).^2))
plot(phi,Omega_B,'LineWidth',2), grid on
Output:
Related
I don't know if this is possible, but I would like to be able to plot contour lines in a given latitude and longitude.
I have an ocean model that gives me the currents in direction u and v at location x (longitude) and y(latitude).
Using the quiver function (quiver(x,y,u,v)) and the following code, I managed to map the currents in the Gulf of Lions.
Step=8 %Only use 1 in 8 data point so the arrows don't overlap too much
figure
q=quiver(lonu(1:Step:681,1:Step:711),latu(1:Step:681,1:Step:711),U,V,0)
As you can see, the model is more detailed close to the coast, because it uses the following grid:
Source: Briton, Florence, et al. "High‐resolution modelling of ocean circulation can reveal retention spots important for biodiversity conservation." Aquatic Conservation: Marine and Freshwater Ecosystems 28.4 (2018): 882-893.
The problem with this is that when I try to use contour or contourf it completely loses the shape of the gulf of Lions due to the choice of grid:
figure
contourf(sqrt(U.^2+V.^2))%The vector of the current is X=sqrt(U^2+V^2) see pythagoras
colorbar
So eventually, I would like to be able to indicate the strength of the current using contourf while indicating the direction using quiver. So how do I reshape the picture given by contourf into something realistic using coordinates?
I checked question Matlab 2D contour using X-Y coordinate data but I don't understand how to use the proposed function.
You suddenly decided to avoid imputing the data that gives the shape, X and Y input parameters.
contourf(lonu(1:Step:681,1:Step:711),latu(1:Step:681,1:Step:711),sqrt(U.^2+V.^2))%The vector of the current is X=sqrt(U^2+V^2) see pythagoras
I have 3D cloud of dots. I need to plot them as a surface. I tried variant with meshdrid, griddata, scatteredInterpolant,trisurf-delaunay. Nothing works. I know that this question was discussed a lot, but it seems I don't understand some important details. The code which i have now:
load('coords.mat')
figure()
subplot(1,2,1)
plot3(x,y,z,'.')
axis off
view(3)
subplot(1,2,2)
C=gray(numel(x)); % unsuccessful attempt
[~,idx]=sort(z); % to have
C=C(idx,:); % illumination
scatter3(x,y,z,50,C,'filled')
axis off
view(3)
produces the following image:
Could you help me:
1) to find a way to draw it with surface function.
and as some dots may be inside the surface (may be it is my problem)
2) How to remove 'invisible' dots?
I need solution for different cases, picture and data presents just an example.
Mat file may be downloaded here.
P.S.
In case it is important – I obtain coordinates of this dots as a rotation of random bezier curve.
UPDATE
In case data above is too big I generate another set with smaller amount of dots:
Coordinates are here.
where do you get this data from? It is represented as vectors but if you reshape it to matrices you can use the surf function. Try this code:
z=reshape(z,100,100);
y=reshape(y,100,100);
x=reshape(x,100,100);
surf(x,y,z)
I am trying to write a MATLAB script to give me a contour map. The contour map must be created from inputs that I generated from 100 images.
The story is like this:
I have 100 images on which I ran an image processing algorithm for optimization. Now, I got their energy curves. So, I have 100 energy curves. I want to create a contour map that will show me where the points are denser on the plot. (the energy curves are plotted as energy vs. iteration with fixed number of iterations)
The following is my variable:
energy(iteration,numImages)
Hope I explained it well.
Thanks in advance.
I interpret your question to boil down to how can I create a surface plot with colors according to the energy found in energy. I would solve this by using the contour function with a grid generated using meshgrid. If each image is described in 1000 data points with 100 files the plot can be generated as follows:
% using stuff as random junk instead of energy
numPoints = 1000;
numFiles = 100;
stuff = rand(1000,100); % replace with actual information
[X, Y] = meshgrid(1:numFiles, 1:numPoints);
contour(X,Y,stuff);
You can also create a 3D surface plot using surf and the same logic.
From what i see of you graph (and using the comments also), one possible way is to use plot3 to plot a line in 3D for every plot.
For doing so, you can use something like this code:
x=(0:0.01:1)';
aexp=zeros(100,numel(x));
hold on
for ii=1:100;
% aexp(ii,:)=exp((-x+ii/10)); %exponential
aexp(ii,:)=exp(-(x-ii/100).^2); %~gaussian
% aexp(ii,:)= x*ii; %linear increase
plot3(x,aexp(ii,:),ii*ones(1,numel(x)));
end
% set(gca,'yscale','log'); % uncomment if you need logscale.
giving
I have a few options of plot. It always plot from the XY view. I changed by hand, but you can use the view command. Notice that i used a simple counter to make the spacing in the z direction.
In a similar manner, you can plot using the contour. For my code, after the data have been generated in the for loop, remove/comment the plot3 and add:
contour(aexp) %outside the for loop,
giving
Notice that i have not really take care what i'm plotting. You can find more info on contour in the Matlab page .
You commented that the x-axis should be number of iterations, y-axis should be energy and z-axis should be the information containing how many lines are passing through from some areas. For this, make a qq variable, being it qq=number_of_lines(number of iterations,energy) . Make a discrete grid for the energy if you don't have one. Number of iterations is probably discrete anyway. The function is you who need to devise, but i would go for something which checks the number of lines for every energy and every iteration. In this case you will have the z-function that depends on y and x, that is the case to use contour or surface.
My function above make a line for every ii point, to have a 3d function. An edition for another extra loop is not hard. Just remember to have the same regular grid for every point, otherwise you will have trouble.
I have used MATLAB to draw the following gain function of an antenna array, the code was as follows,
Nt=8;
deltat=1;
Lt=8;
omegat=-2:0.01:2;
for j=1:length(omegat)
gainfunction(j)= (1/Nt) * exp(i*pi*deltat* omegat(j)* (Nt-1)) * (sin(pi*Lt*omegat(j))/sin(pi*Lt*omegat(j)*Nt^-1));
end
plot(omegat,abs(gainfunction))
title( 'Radiation Pattern Cartesian Plot','linewidth',30)
grid on
ylabel('|f(\Omega_r)|','linewidth',25)
xlabel('\Omega_r','linewidth',15)
The image below is a radiation pattern of an antenna, i.e it shows the gain function denoted by |f(\Omega)| as function of $\Omega$ from -2 to 2.
My question is I would like to plot the following in polar coordinates to see how the main lobe is in degrees.
Any thoughts on how I can continue to the polar plot using MATLAB ?
polar (omegat*pi/2, abs(gainfunction));
I scaled omegat by pi/2 because I'm not sure what your convention here is. I'm assuming omegat must range from -pi to +pi and hence, I've scaled it by pi/2. Modify the scaling as you see fit.
Also, don't use i or j as loop counters in matlab. They're used in many places as iota or the sq root of minus one.
I am trying to write a matlab code to model the projectile motion of a cannon shell including the effects of air drag and air density that changes with respect to temperature, however the code I have so far only computes a straight line for the shell trajectory which is incorrect. Can anyone point out where I have gone wrong and point me in the right direction to include the effect of air density and temperature? Thanks.
clear;
%input parameters
v0=input('Enter the muzzle velocity (m/s) ');
theta=input('Enter the quadrant elevation (degrees) ');
%T0=input('Enter the value for the ground temperature in degreees ');
%T0=T0+275.16;
b2bym0=4e-5;
g=9.8;
dt=1e-2;
%define initial conditions
x0=0;
y0=0;
vx0=v0*cosd(theta);
vy0=v0*sind(theta);
fdragx=-b2bym0*v0*vx0;
fdragy=-b2bym0*v0*vy0;
n=1000; %iterations
%Tratio=(T0/300)^(2.5);
%define data array
%t=zeros(1000);
x=zeros(1000); %x-position
y=zeros(1000); %y-position
vx=zeros(1000); %x-velocity
vy=zeros(1000); %y-velocity
for i=1:n
t(i)=i*dt;
vx(i)=vx0+fdragx*dt;
vy(i)=vy0+fdragy*dt;
x(i)=x0+vx(i)*dt;
y(i)=y0+vy(i)*dt;
x0=x(i);
y0=y(i);
vx0=vx(i);
vy0=vy(i);
end
plot(x,y,'g+')
it doesn't look like you are modeling the downward acceleration of g force for your y velocity
Looks like there were three issues.
First you missed gravity in updating vy. Fixed
Second drag force was not updating with the velocity. Fixed
Thirdly, your calculating the new position/velocities using the initial values and not the previous ones. In the loop try changing these lines. You might have to update your for loop to go from 2:n if matlab indexes at 1.
vx(i)=vx(i-1)+fdragx*dt;
vy(i)=vy(i-1)+(-g+fdragy)*dt;
x(i)=x(i-1)+vx(i)*dt;
y(i)=y(i-1)+vy(i)*dt;
Edit:
Didnt see the update of the initial conditions, disregard the third comment.