Hi, i need to write function for the following.(adsbygoogle = window.adsbygoogle || []).push({});

W=k1x if x<d

W=k1x+2k2(x-d) if x>=d

Question is: Create function that computes distance x using the input parameters W, k1, k2, and d.

k1=10^4

k2=1.5*10^4

d=0.1

W=500 and 2000

so i get the formulas solving for x that are

x=W/k1 and x=(W+2k2d)/(k2+2k2)

but I dont know how to solve for x as I get error which says that x is not defined when i use if/else and i tried using for loop and got the same problem.

here is my code:

function x = spring (W)

k1=10^4;

k2=1.5*10^4;

d=0.1;

if x < 0.1

x=W/k1

else x >= 0.1

x=(W+(2*k2)*d)/(k1+(2*k2))

end

Any help please?

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab function HW help please

Loading...

Similar Threads for Matlab function help | Date |
---|---|

Help: MATLAB time step function | Jan 11, 2015 |

MATLAB help: Interpolating an array of data to create a function | Dec 29, 2012 |

Matlab help! User defined function! | Nov 7, 2012 |

Matlab help error : Undefined function or method 'rcpulse' for input arguments of typ | Mar 21, 2012 |

Help with function in Matlab | Mar 20, 2012 |

**Physics Forums - The Fusion of Science and Community**