Equation to Matlab code

2 ビュー (過去 30 日間)
Lucca Martinelli
Lucca Martinelli 2021 年 4 月 5 日
コメント済み: Lucca Martinelli 2021 年 4 月 5 日
Hey, I need to write the following equations in MATLAB code. I can't find a mistake, but the displayed results are also not what I was expecting.
Could someone check for me maybe?
This is what I wrote:
y1 = (-W.*x1)./(384*E*I).*(16.*x1.^3-24*L.*x1.^2+9*L^2)+(M.*x1)./(6*E*I*L).*(x1.^2-3*L.*x1+2*L^2);
y2 = (-W*L)/(384*E*I).*(8.*x2.^3-24*L.*x2.^2+17*L^2.*x2-L^3)+(M.*x2)./(6*E*I*L).*(x2.^2-3*L.*x2+2*L^2);
  3 件のコメント
Lucca Martinelli
Lucca Martinelli 2021 年 4 月 5 日
I am dealing with vectors but I believe that inser the dots in every important place, I will try putting some extra dots and check the difference. Thanks
Image Analyst
Image Analyst 2021 年 4 月 5 日
  1. What were your input variable values?
  2. What did you get?
  3. What were you expecting?
Here is the pointing guideline FAQ again:
Also, I'll format your code as code by clicking on the Code icon, hopefully it's something you'll do yourself next time.

サインインしてコメントする。

採用された回答

John D'Errico
John D'Errico 2021 年 4 月 5 日
編集済み: John D'Errico 2021 年 4 月 5 日
ALWAYS show what you wrote. Ony you know what you mean by dealing with vectors, etc. In the first case, do you have a vector of values for x, that varies from 0 to L/2?Are L, M, W, E, I all known constants with given values?
W = ???; % I've not filled these in because I have no idea what values you have
E = ???;
I = ???;
M = ???;
L = ???;
n = 100;
x1 = linspace(0,L/2,n);
First, you need to learn WHEN to use the dotted operators. You only need them when you are multiplying or dividing vectors or arrays of elements, or raising to powers. That tells MATLAB to perform element-wise operations.
However, you can multiply a vector by a scalar or multiply two scalars with no problem.
You can also divide a vector by a scalar using /, but you cannot divide a vector INTO a scalar using the / operator. That is if x is a vector, and a is a scalar, you can do these things using * or / :
x/a
x*a
a*x
because a is a scalar.
However to divide a scalar by a vector, you need to use ./ :
a./x
To raise elements to a power, you use .^ , thus you would do:
x.^a
a.^x
Raising a scalar to a scalar power is no problem. However
Addition and subtraction are always no problem. There is no .- or .+ operator to worry about.
Given all that, y1 should look like this:
y1 = (-W*x1)/(384*E*I).*(16*x1.^3-24*L*x1.^2+9*L^2)+(M*x1)/(6*E*I*L).*(x1.^2-3*L*x1+2*L^2);
  3 件のコメント
Walter Roberson
Walter Roberson 2021 年 4 月 5 日
Well, it is a plot. We do not know what you were expecting.
If your constants are correct then y2 at L/2 is slightly negative.
L = 20;
E = 200e9;
I = 348e-6;
W = 5.4e3;
M = 200e3;
x1 = linspace(0,L/2);
x2 = linspace(L/2,L);
y1 = (-W.*x1)./(384*E*I).*(16.*x1.^3-24*L.*x1.^2+9*L^2)+(M.*x1)./(6*E*I*L).*(x1.^2-3*L.*x1+2*L^2);
y2 = (-W*L)/(384*E*I).*(8.*x2.^3-24*L.*x2.^2+17*L^2.*x2-L^3)+(M.*x2)./(6*E*I*L).*(x2.^2-3*L.*x2+2*L^2);
x = [x1 x2];
y = [y1 y2];
plot(x,y)
Lucca Martinelli
Lucca Martinelli 2021 年 4 月 5 日
Thanks a lot!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by