Error using mtimes (inner dimension must agree)

Dear all, Kindly help me with this issue. Below is my screenshot of the coding.
if true
function [ theta, E, D,FL] = OP1(AngleMax,necktodiameter,alpha,beta)
global a b
a = 52; %fixed at a rate of 52 degree
b = 15; %fixed at a rate of 15 degree
theta = (AngleMax)-(2*asind(1./(necktodiameter)));
E = cosd(theta/2) - sind(alpha).*cosd(beta).*cosd(a).*cosd(b);
D = ((1-((sind(alpha)).^2*(cosd(beta).^2).^2))*(1-(cosd(a)).^2*(cosd(b).^2))) - E.^2;
FL = acosd((((((-sind(beta)).*(cosd(a)).*(sind(b))) + ((cosd(alpha)).*(cosd(beta)).*(sind(a)))).*E) - ((((cosd(alpha)).*(cosd(beta)).*(cosd(a)).*(sind(b)))+((sind(beta)).*(sind(a)))).*sqrt(D)))./((1-sind(alpha).^2.*cosd(beta).^2).*(1-cosd(a).^2.*cosd(b).^2)));
end

2 Commenti

Stephen23
Stephen23 il 10 Feb 2015
Modificato: Stephen23 il 10 Feb 2015
Dear FarisM,
we are happy to help you with your questions, but it would be a great help for us if you learned to include code as text, and not as screenshots. Screenshots actually just makes it harder for us to help you. When you are writing your question (or comment), you will see below the text box a preview box: this shows how your question will look when you post it. Then above the text box you will find several buttons: the one you really need to learn how to use is labebelled {} Code. Please use this button to format your code as text, and do not include it as screen shots. If the code is large, it is preferred that you upload it using the paperclip button instead. This might also be of interest:
Have fun learning about MATLAB!
Dear Mr Stephen,
Thank you for your information as I've beginner on asking from this website. Will be alert next time. Thank you sir.

Risposte (2)

Michael Haderlein
Michael Haderlein il 10 Feb 2015
Modificato: Michael Haderlein il 10 Feb 2015
Posting a screen shot is not so helpful. It's much easier for us to help if we can simply copy-paste the code into our command window.
Anyway, one dot is missing when you calculate FL. Instead of
/((1-sind(alpha).^2*cosd(beta).^2
it needs to be
./((1-sind(alpha).^2*cosd(beta).^2

1 Commento

First of all, sorry because im not sure how to write in here. After your recommendation, I altered the coding. But the value of FL is only "one" instead of two if I put this [ theta, E, D,FL] = OP1(180,2,35,[10,15]) in command. Help me sir.
function [ theta, E, D,FL] = OP1(AngleMax,necktodiameter,alpha,beta) global a b a = 52; %fixed at a rate of 52 degree b = 15; %fixed at a rate of 15 degree
theta = (AngleMax)-(2*asind(1./(necktodiameter))); E = cosd(theta/2) - sind(alpha).*cosd(beta).*cosd(a).*cosd(b); D = ((1-((sind(alpha)).^2*(cosd(beta).^2).^2))*(1-(cosd(a)).^2*(cosd(b).^2))) - E.^2; FL = acosd((((((-sind(beta)).*(cosd(a)).*(sind(b))) + ((cosd(alpha)).*(cosd(beta)).*(sind(a)))).*E)... - ((((cosd(alpha)).*(cosd(beta)).*(cosd(a)).*(sind(b)))+((sind(beta)).*(sind(a)))).*sqrt(D))).... /((1-sind(alpha).^2.*cosd(beta).^2).*(1-cosd(a).^2.*cosd(b).^2)));
Torsten
Torsten il 10 Feb 2015
E=cosd(theta/2)-sind(alpha).*cosd(beta).*cosd(b);
Best wishes
Torsten.

4 Commenti

Dear sir, as your recommendation, I altered the coding. But the value of FL is only "one" instead of two if I put this way [ theta, E, D,FL] = OP1(180,2,35,[10,15]) in command. Help me sir. You did help me before. Thank you
function [ theta, E, D,FL] = OP1(AngleMax,necktodiameter,alpha,beta) global a b a = 52; %fixed at a rate of 52 degree b = 15; %fixed at a rate of 15 degree
theta = (AngleMax)-(2*asind(1./(necktodiameter))); E = cosd(theta/2) - sind(alpha).*cosd(beta).*cosd(a).*cosd(b); D = ((1-((sind(alpha)).^2*(cosd(beta).^2).^2))*(1-(cosd(a)).^2*(cosd(b).^2))) - E.^2; FL = acosd((((((-sind(beta)).*(cosd(a)).*(sind(b))) + ((cosd(alpha)).*(cosd(beta)).*(sind(a)))).*E)... - ((((cosd(alpha)).*(cosd(beta)).*(cosd(a)).*(sind(b)))+((sind(beta)).*(sind(a)))).*sqrt(D))).... /((1-sind(alpha).^2.*cosd(beta).^2).*(1-cosd(a).^2.*cosd(b).^2)));
Hi Faris,
a general advice: it sometimes helps to split the computation up using intermediate variables, it makes everything much easier to read (and as a consequence, to debug) ...
Titus
Dear Mr Titus,
What did you suppose to mean by intermediate variables? Is it mean by putting '...' to avoid long equation? Sorry as I'm new in Matlab. Hope you might help me.
Regards
D = ((1-((sind(alpha)).^2.*(cosd(beta).^2).^2)).*(1-(cosd(a)).^2.*(cosd(b).^2))) - E.^2
My advice:
Change all "/" or "*" or "^2" to "./" or ".*" or ".^2" in your code.
Best wishes
Torsten.

Questa domanda è chiusa.

Prodotti

Richiesto:

il 10 Feb 2015

Chiuso:

il 20 Ago 2021

Community Treasure Hunt

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

Start Hunting!

Translated by