Writing a Function for Plotting
Show older comments
Hello, Here is a link to my assignment.
I need help with the second part. The first part was simple. Here is what I have.
function spring(W,k1,k2,d)
if (x<d)
x= W/k1
else (x >=d)
x=(W+ (2 .* (k2) .* d)/((k1) + (2.*(k2))))
end
How would I plot this? See link as reference.
Thanks for help in advance.
Accepted Answer
More Answers (1)
Big Meech
on 24 Apr 2011
2 Comments
Big Meech
on 24 Apr 2011
Paulo Silva
on 24 Apr 2011
Like I said before you don't need that elseif condition, just put else there, also your function must return something, in that case it should return the x value, and finally you should put the ; after the x value assignment (no x value will appear on the command window)
function x=spring(W,k1,k2,d)
if ((W/k1)<d)
x= W/k1;
else
x=(W + 2*d*k2)/(k1 + 2*k2);
end
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!