Matlab only outputs one variable, and doesn't plot a line.
3 views (last 30 days)
Show older comments
Trying to plot corner speed vs mass of a vehicle. But when I plot I don't get a line.
%% once this works, add a user defined input for radius
mu = 1; %%Coefficient of friction
r =80; %% the regular line radius is 30m, the racing line is 80m
g = 9.81; %%Gravitational constant
%%m = x;
x = 1000:50:1250 %% car mass for the input roughly 2000-2800 lbs
y = sqrt((mu*(x*g)*r)/x) %% calculates velocity in Meters / second
Where I would expect it to enter the series of x into the equation y= sqrt... , it displays x 1000, 1050 etc in the workspace, but only displays y as 28.0143, which I would expect if it was ONLY calculating the 1000kg value. and not the expected 1000, 1050, 1100, 1150, 1200, 1250 inputted into x of the equation.
5 Comments
Stephen23
on 10 Aug 2019
"You said I made it a matrix and not a vector"
Not at all: I have not written anything about what you "made". Here is the full quote of the first sentence of my first comment: "Read about the differences between matrix operations (what you used) and array operations (what you should have used)"
I wrote that you used the wrong type of operator, and I did not mentioned vectors anywhere.
In particular, I wrote that you used a matrix operation, whereas you should have used an array operation. I gave the link to the documentation page that explains the differences: there are five operators which have matrix/array versions, and you used two of them (i.e. * and /). A very short summary of the differences between array operations and matrix operations:
- array operations are element-wise.
- matrix operations are for linear algrebra.
"Considering you are ranked 5th in answers... I find that hard to believe with that reply."
I understand that you are frustrated and are struggling to make your code work, but taking that out on the volunteers who are trying to help you is not appreciated, nor is it likely to help.
Consider also my perspective: when I write a reply to someone, I usually have no idea if they have years of experiences or none, if they can glean information from reading documentation themselves or if they require information to be spoon-fed, etc. I am happy to adapt my advice if they give feedback, but there is no magic way that I can read minds and know exactly what level of advice to offer, or exactly which exact bits they do not understand (use of different terminology often makes that even harder). I have to guess based on the kind of problem they are having or they way they ask... but even these are only proxys at best.
I just noticed that in your code you divide x by x:
sqrt((mu*(x*g)*r)./x) % array division.
% ( ^ ) % vector x
% ^^ % divided (element wise) by
% ^ % vector x
Because mu, r, and g are scalars which multiply to some value k, your code is bascially equivalent to this:
sqrt(k*x./x)
Which, for finite values x./x will return an array of 1's the same size as x:
>> x = 1000:50:1250;
>> x./x
ans =
1 1 1 1 1 1
and so your code is basically doing this:
k * ones(size(x))
What is the exact formula that you are trying to implement ? Does it really divide x by x ?
Answers (1)
KALYAN ACHARJYA
on 9 Aug 2019
Edited: KALYAN ACHARJYA
on 9 Aug 2019
y = sqrt((mu*(x*g)*r)./x) %% calculates velocity in Meters / second
%....................^.........
Now
x =
1000 1050 1100 1150 1200 1250
y =
28.0143 28.0143 28.0143 28.0143 28.0143 28.0143
Please check, why it giving constant value? Plot will be horizantal line.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!