Invalid expression please fix :(

%given data
a = 45; % Angle in degrees
P = 100; % Load in Newtons
h = 1.0; % Truss height in meters
% Calculate horizontal and vertical components of the load
P_horizontal = P * cosd(a);
P_vertical = P * sind(a);
% Calculate reactions at supports
G_x = P_horizontal;
G_y = P_vertical;
% Calculate forces in members
BC_y = G_y;
BC_x = 0;
CL_y = BC_y;
CK_y = 0;
CD_x = 0;
EF_x = 0;
EF_y = 0;
KL_x = 0;
KL_y = 0;
% Display results
fprintf('Forces in Members:\n');
Forces in Members:
fprintf('BC: %.2f N (compression)\n', BC_y);
BC: 70.71 N (compression)
fprintf('CL: %.2f N (tension)\n', CL_y);
CL: 70.71 N (tension)
fprintf('CK: Zero force member\n');
CK: Zero force member
fprintf('CD: %.2f N (tension)\n', CD_x);
CD: 0.00 N (tension)
fprintf('KL: Zero force member\n');
KL: Zero force member
fprintf('EF: Zero force member\n');
EF: Zero force member

12 Comments

Works for me. Where do you get a problem ?
can you give me a step by step from you opening the app to you running the code? would be greaty appreciated
@habib If you have any more questions, then tell us what numbers you entered, and the entire error message (ALL THE RED TEXT, not just a snippet from it so we know what line threw the error) after you read this:
Line 26 :parse error at N : usage mgiht be invalid MATLAB syntax
As you can see, the code you have posted above runs without any error.
This means that the code you are running on your PC is different.
Post the whole code you are working with.
that is whole code i just a mac does that make a difference? even thou im running a msac version?
if possible can u post screenshots of what the code ran thank you
That is the beauty of Matlab: the operating system hardly ever matters.
The code you posted will run on any OS. Since the code you are trying to run doesn't, that means there is a difference. Please show the contents of the entire file you are trying to run. Without that, we will be running around in circles. As you can see in the question post itself: your code will run in R2023a. If you edit it and rerun, you can confirm it als runs in R2023b.
Torsten
Torsten on 15 Sep 2023
Edited: Torsten on 15 Sep 2023
The formating of the code you posted originally shows that you entered every line of your code in the command mode. Save the complete above code in an .m-file and run it from your MATLAB editor by pressing the green RUN arrow.
Line 26 is
fprintf('CK: Zero force member\n');
I see no problem with that or even any mention of N. The entire code runs fine in r2023b (now available for download). Try retyping the line because maybe you have some funky unicode character in there (perhaps even invisible). Attach screenshots if it still doesn't work.
ive tried it all still doesnt run, ive given up if you can send screenshots of code running that would be helpful
One of the moderators edited your post to format your code and run it here on MATLAB Answers. Because of that, your Question is now effectively a screen capture of the output of the code as if you had run it as a Livescript.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 17 Sep 2023
"can send screenshots of code running that would be helpful".
It runs fine in r2023a and r2023b (see below). Now it's your turn to attach screenshots.

Categories

Find more on Text Analytics Toolbox in Help Center and File Exchange

Asked:

on 14 Sep 2023

Answered:

on 17 Sep 2023

Community Treasure Hunt

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

Start Hunting!